HTML uses the language attribute (“lang”) to specify the language in a web page. It can be set for any HTML element thereby assisting a browser in rendering the language content. The “lang” attribute is used to ensure the following:
- To orient and adapt to the pronunciation and syntax that are specific to the language of the page.
- Screen readers can pronounce words in the appropriate foreign language if it is specified.
Guideline:
-
Use the language attribute on the <html> element to identify the primary language of each document, for example, <html lang="en">, for English. Use the language attribute on
<span> or other elements to identify words or phrases in other languages
Note: Not all screen readers support automatic language changes, but setting the “lang” attribute will not negatively affect those.
Validation Technique:
- If the content is HTML, check for the html element's lang attribute
- If the content is XHTML 1.0, check for both the html element's lang attribute and XML: lang attribute
- If the content is XHTML 1.1 or higher, check for the html element's XML:lang attribute