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
langattribute to the<html>element with a valid language code. For example, for English:Copy<html lang="en"> <!-- document head and body --> </html> - 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
langattribute on the relevant elements:Copy<p>This is an English paragraph.</p> <p lang="es">Este es un párrafo en español.</p> -
For languages written right-to-left, also include the
dirattribute:Copy<p lang="ar" dir="rtl">نص باللغة العربية هنا</p>
Other Rules
Interested in other web accessibility rules? Please see these other rules: