You are here:
- Manual
- Development
- Languages
- Base language
Languages: The base language of a page
Web developers must specify the base language of a page in the markup. This has to be applied once in the <html> element, through the lang attribute.
Specify the base language of a page in the markup.
Guidelines R-pd.15.6
In HTML
<html lang="en">
In XHTML
<html lang="en" xml:lang="en" ...>
The value of the lang attribute is a language code of two and sometimes three letters, according to the ISO 639 Language Codes specification. Preferably use the two letter codes (ISO 639-1). These codes represent modern, spoken languages.
The three letter codes in ISO 639-2 are bibliographic language codes, many of them are classical languages. Use these when there is no two letter language code from ISO 639-1 available.
In future versions of XHTML, the lang attribute will be replaced by the xml:lang. In XHTML 1.0, the lang attribute is still present for reasons of compatibility with systems that don't understand XHTML. However, XHTML has its own attribute for language variations: xml:lang. For the sake of compatibility with browsers that do not understand XHTML, both attributes with the same value must be used. See also Page structure.
The benefits
- Screen reader programmes can adapt their pronounciation to the specified language.
When the language variation is not specified, the programme will have to guess. Alternatively, it must ask the user to intervene. - Search engine spiders can conclude from the markup in what language the page content is written.
Search engines can allow visitors to filter search results according to the language of their preference. Search engines may guess what the language is if the markup not specify this (domain name, words in the content), but this may result in, for example, Dutch pages being interpreted as being German. - Browsers and other programmes can perform spell checks and translations more easily.
“Use both the lang and xml:lang attributes when specifying the language of an element. The value of the xml:lang attribute takes precedence.”
‘The lang and xml:lang Attributes’, W3C XHTML specification, Appendix C
