Rule ID: html-lang-valid
Ruleset: axe-core 4.10
User Impact: Serious
Guidelines: WCAG 2.1 (A), WCAG 2.0 (A), WCAG 2.2 (A), Trusted Tester, EN 301 549
How to Fix the Problem
Ensure the <html>
element in your document has a lang
or xml:lang
attribute that correctly specifies the primary language of the content.
Examples:
For a document primarily in English:
For a more specific dialect:
If the Language Changes Within the Page:
Use the lang
attribute on inline elements:
For Right-to-Left Languages:
Use the dir
attribute to define text direction:
For left-to-right languages (optional if already default):
Best Practices:
-
Always spell the language code correctly.
-
Use IETF BCP 47 language tags (e.g.,
en
,fr-CA
,zh-Hans
). -
Don’t guess—ensure the specified language truly represents the primary content of the document.
Why it Matters
Screen readers and other assistive technologies rely on the lang
attribute to determine how to pronounce text. If this attribute is missing or incorrect:
-
The screen reader defaults to the user’s system language, which may mispronounce words and confuse the user.
-
Multilingual users may not understand the content if it’s spoken in the wrong language library.
-
Proper language tagging enables accurate voice intonation, pronunciation, and comprehension.
Correctly specifying the language allows users—especially those who are blind or visually impaired—to interact with web content as intended.
Rule Description
Each HTML document must include a lang
(or xml:lang
) attribute in the opening <html>
tag with a valid language code. This ensures the content is interpreted correctly by screen readers and improves accessibility for multilingual users.
The Algorithm (in Simple Terms)
-
Check if the
<html>
element contains alang
orxml:lang
attribute. -
Verify that the value of the attribute is a valid language code (e.g., “en”, “es-ES”, “fr-CA”).
-
If either the attribute is missing or the value is invalid, the page fails the check.