Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
When humans communicate, they use language, like right now I'm speaking to you in English. I could speak to you in the Norwegian. (Norwegian dialogue) Things are no different when it comes to the Web. When we publish content to the web and people read it, they quickly recognize the language it was written in. But computers aren't always that smart. To help them, we can add a piece of code in the header of our pages that tells the browsers and search engines what language the content is written in. This has some surprising benefits.
What we want to do is tell the browser and the search engines what language the content is written in. Now when I say language, I mean the language the content is written in, not the code language. The accessibility benefit of this is twofold. First of all browsers can detect the language and offer to translate the content on that page. You may have noticed that Google Chrome, in particular, wants to translate content you visit in another language. Now, Google Chrome is actually tracking the language on the page itself and making a guess, but other browsers and future browsers will be tracking the language code that's embedded into your content.
In addition, text-to-speech browsers can read back the text in the correct language. So if you wrote something in English it'll read it back in English. If you wrote it in German or in Norwegian, it'll read it back in German or Norwegian. This is really important because you can actually embed multiple language codes in one page. So, for instance, if you had a page that was mostly written in English but had a quote in French, you could define that quote as French text, and the Text-to-Speech browser would then notice that and switch over the languages.
The SEO benefit is quite interesting. Search engines index pages based on the language the content is written in. That means when you make a search on Google for instance, you can say, I only want to see results written in a specific language. By default, it will default to the language you search in, but you can go and search for a different language. That also means if you define the wrong language for your page or you don't define a language for your page, your page may not appear in searches that are targeting a specific language. So how do we declare a language for a page? It's really simple.
At the very top of your page you have an HTML tag. What you want to do is add to the html tag the variable lang= and then whatever language code you want to use. You notice here I've also added the direction attribute, because some languages are written right to left, and you can define that specifically in the HTML as well. The world is populated with people who speak many different languages and when we use the language tag, we need to target those specific languages. There is an ISO language code that targets different languages, and if you want to find a specific language, you can go to the w3schools.com site and find the HTML language code reference, where you have a complete list of all the standard languages.
You can see here it goes all the way from A to Z. Now it's worth noting that in addition to the standard languages, you also have variables. For instance, you noticed in my slide, it said en-US, because this is US English. You can also say en-CA, for Canadian English, and so on. Now we're going to implement this into our example project and add a language code to it. But before we do that I have to build my example project. So I'll go to the Exercise Files and under Assets you find a folder called Starting Point. So I'll simply drag this one out to my desktop, copy it to my desktop, and this is where we'll doing all of work from now on.
So I'll change the name of this folder to something else. I'll call it My Accessible Site. I can open it, and here you see we have the index HTML file. This is the one page in my project. We also have the general CSS styles, and a style reset that makes sure that this looks the same across all browsers. And finally, there is a folder for images. So I want to open index.html in Notepad++ so that I can start working with it.
This is HTML5, which means the Doc Type definition is just DocType html, and then right underneath, we have the html tag. So here, all I need to do is say, dir="LTR", because it's left to right, and then lang="en-US". When I save this, I tell the browser and the search engine that the text on this page is written from left to right and that the language is US English.
Adding a language tag to your page is easy and has a huge advantage, both for accessibility and for SEO. In addition, you add current and future features to the sites by providing language info, so applications can identify and use this info on the site.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97505 Viewers
80 Video lessons · 141050 Viewers
59 Video lessons · 59400 Viewers
52 Video lessons · 72723 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.