Back to Info and Examples for Accessibility Insights for Web
html-lang-valid
The lang
attribute of an <html>
element must have a valid value.
Why it matters
When a web page’s primary language is programmatically identified, browsers and assistive technologies can render the text more accurately; screen readers can use the correct pronunciation; visual browsers can display the correct characters; media players can show captions correctly; and automated translation is enabled.
All users find it easier to understand the page’s content.
How to fix
Provide a valid lang
attribute value:
- Identify the page’s primary language.
- Choose the corresponding a language code from the IANA Language Subtag Registry
- Make sure the value is spelled correctly.
Example
Fail
<html>
element has the wrong lang
attribute for Spanish.
As a consequence, screen readers don't use the correct pronunciation, and users struggle to understand the content.<html lang="sp">
Pass
<html>
element has the correct lang
attribute. It correctly identifies the primary language of the page as Spanish.
Screen reader users find the content easier to understand because it's pronounced correctly.<html lang="es">
About this rule
This rule passes if:
- The
<html>
element’slang
attribute has a valid value