Optimization of the language Tag

What is the language tag?

The language tag is a HTML element that should be placed in the head section of your webpage. It states the language of the text of the page it is included on, so search engines can recognize the language of a page. The Internet of Bots offers a full tutorial about how to correctly implement this language tag, by which users and search engines can make the best use of this part of a website.


How is it used?

  1. The language tag should be placed within the <head> section.
  2. You don´t have to close the tag: <html lang="en"></html lang>.
  3. Make sure there is (only) one language tag per page.
  4. As a HTML element, the tag should be declared by name and content. Remember to place the information between quotation marks: <html lang="en">
  5. <head>
    <html lang="en">
    </head>

  6. 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
  7. <head>
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    </head>

  8. 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:
  9. <body>
    <p>If you want to translate the word "Language" to Dutch, you get: <span lang="nl">Taal</span><.p>
    </body>

  10. 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?

  1. Make sure every page of the site has a language tag
  2. Check the validity of your tag using a system such as the Language subtag lookup
  3. 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>:

<!DOCTYPE html>
<html lang="en">
<head>
[...]

Suggestions:

  • Open a website and view its sourcecode. Here you can see how the website has defined its language tag.

External references:

  1. w3schools on language codes
  2. Choosing a language tag
  3. Language subtag lookup