Ensure the lang Attribute of the <html> Element Has a Valid Value

Photo of Researcher
Yotam Flohr
Researcher
Blind Hearing
WCAG 2.1 Level A

Written and researched for humans by humans

Photo of Researcher
Yotam Flohr
Researcher
Photo of Expert
Ritvik Shrivastava
Expertly reviewed by
Comments: 0
Your entire domain
Get detailed instructions on how to resolve every accessibility issue on your website

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.

Why It Matters

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. 

Fixing the Issue

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. 

Good Code Example

Code example
<html lang="en"> <!--document head and body--> </html> Copy

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:

Code example
<p lang="ar" dir="rtl">Arabic text here</p> Copy

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”.

Test Cases

For more examples, visit W3C’s GitHub’s ATC Rules library