Web accessibility standards state that an HTML document must contain a valid lang attribute or must correspond to a valid lang code for multilingual screen reader users.
When setting up a screen reader, users need to select a default language. When a website’s language is not specified, the screen reader will use the default language as set by the user.
By setting the language of a web page, you ensure content is pronounced correctly.
Add a lang or xml:lang attribute to the html element (e.g. <html lang=”en”> or <html xml:lang=”en”>) that represents the primary language of the document.
Make sure you identify a language in the opening <html> element and spell the attribute correctly.
You can even specify some dialects with codes such as “en-US” to highlight American English or “fr-CA” for Canadian French.
If the language changes within a document, you can specify this as follows:
<p>Text in one language <span lang=”es”>text in another language</span></p>
If you are using a language that is written right to left, be sure to specify this using the dir attribute:
If you would like to specify that a language is written left to right, you can fill the value of the dir attribute with the value “ltr”.
For more examples, visit W3C’s GitHub’s ATC Rules library.