Ensure the lang attribute of the <html> element has a valid value
Ensure that the <html>
element includes a lang
attribute with a valid language code to specify the primary language of the document.
About This Rule
This rule ensures that the <html>
element contains a valid lang
attribute, facilitating proper language identification for assistive technologies and enhancing accessibility for multilingual users.
Why It Matters
Screen readers and other assistive technologies rely on the lang
attribute to determine the language of the content, enabling accurate pronunciation and interpretation. Without this attribute, or if it contains an invalid value, users may experience incorrect pronunciation, leading to confusion and a diminished user experience.
How to Fix
To specify the primary language of your document:
-
Add a
lang
attribute to the<html>
element with a valid language code. For example, for English: - For regional dialects, use appropriate language codes, such as "en-US" for American English or "fr-CA" for Canadian French.
-
If the document contains sections in different languages, specify the language for those sections using the
lang
attribute on the relevant elements: -
For languages written right-to-left, also include the
dir
attribute:
Other Rules
Interested in other web accessibility rules? Please see these other rules: