How is it used?
- The language tag should be placed within the <head> section.
- You don´t have to close the tag: <html lang="en"></html lang>.
- Make sure there is (only) one language tag per page.
- As a HTML element, the tag should be declared by name and content. Remember to place the information between quotation marks: <html lang="en">
- As a XHTML element, in case you use XHTML, the tag should be declared by name and content, but should also contain a reference to xmlns and xml:lang
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
- If you are using multiple languages on the same page, it is possible to declare the language within a HTML element. The best practice would be to declare the main language within the <head> and declare the alterations as follows:
<p>If you want to translate the word "Language" to Dutch, you get: <span lang="nl">Taal</span><.p>
- For some languages it might be usefull to add a subtag. There are different forms of subtags, such as Macrolanguages and Primary Languages ("ar" is for the general (macro)language Arabic and "ssh" is for the primary language Shihhi Arabic), Extended language subtags ("asf" is for Australian sign language) or Regions ("en-GB" is for English as spoken in Great Brittain (note that the sub of a region should be in capital letters)). It doesn't matter which one you choose as long as you pick a correct statement. Use the Language subtag lookup for a full reference of the thousands of possible statements or read Choosing a Language Tag for a series of recommendations.
Why is it important?
- Search engines will use the language tag to enlist the language of your site
- Software that enables users to translate a site to a preferred language will use the language tag to define the starting language.
- Speaking software will use the language tag for their configuration on your page.
What can I do to check if my language is good?
- Make sure every page of the site has a language tag
- Check the validity of your tag using a system such as the Language subtag lookup
- Make sure the tag is defined correctly (see ´How is it used?´)
What is the exact position to place the tag?
This is a difficult question, since different developers have different opinions. The main thing is to place the title tag in (the top) of the head section. The Internet of Bots uses the following order as proposed bij Bootstrap 3, which places the tag imediately after the <!DOCTYPE html>:
- Open a website and view its sourcecode. Here you can see how the website has defined its language tag.
- w3schools on language codes
- Choosing a language tag
- Language subtag lookup