Back to Info and Examples for Accessibility Insights for Web
valid-lang
The lang
attribute must have a valid value.
Why it matters
Sometimes a web page written in one language has a passage in a different language. When the language of such a passage is correctly identified (by a lang
attribute on the containing element), browsers and assistive technologies can render the text more accurately; screen readers can use the correct pronunciation; visual browsers can display the correct characters; and media players can show captions correctly. All users find it easier to understand the content.
How to fix
Provide a valid lang
attribute value:
- Identify the passage’s language.
- Choose the corresponding language code from the IANA Language Subtag Registry
- Make sure the value is spelled correctly.
Example
Fail
<html lang="en-US>
…
<body>
…
<span id="original">The quick brown fox jumps over the lazy dog.</span>
…
<span id="translation" lang="sp"> El rápido zorro marrón salta sobre el perro perezoso.</span>
Pass
<html lang="en-US>
…
<body>
…
<span id="original">The quick brown fox jumps over the lazy dog.</span>
…
<span id="translation" lang="es"> El rápido zorro marrón salta sobre el perro perezoso.</span>
About this rule
This rule passes if:
- The
lang
attribute has a valid value