html-xml-lang-mismatch
Web validation
<html> tag has lang and xml:lang attributes, both attributes must carry the same valid language code.All pages need a single, reliable primary language indicator. When both lang and xml:lang are present, they have to match so that browsers, search engines, and assistive technology switch to the correct language profile. A mismatch can send a screen reader to the wrong voice, hamper spell-checking, and mislead translation tools.
Pass Patterns
Matching lang and xml:lang values
The lang and xml:lang values are identical and use the two-letter tag en that is part of the ISO 639-1 list.
<!DOCTYPE html>
<html lang="en" xml:lang="en">
<head>
<meta charset="utf-8">
<title>Matching language codes</title>
</head>
<body>
…
</body>
</html>Fail Patterns
lang and xml:lang values do not match
lang and xml:lang exist but disagree, forcing assistive technology to guess which one is right.
<!DOCTYPE html>
<html lang="en" xml:lang="fr">
<head>
<meta charset="utf-8">
<title>Mismatching language codes</title>
</head>
<body>
…
</body>
</html>Try It Yourself
Inspecting the browser dev-tools
- Open the page in a browser.
- Open Developer Tools and switch to the Elements panel.
- Select the root
<html>element and look at thelangandxml:langattributes.
Expected result: Both the lang and xml:lang attributes carry the same value.
Actual result: The lang and xml:lang attributes have different values.
FAQ
How does this issue relate to 3.1.1 Language of Page?
SC 3.1.1 requires that the page’s default human language be programmatically determinable. When lang and xml:lang disagree, user agents cannot tell which value to trust, so the success criterion fails.
Why is this issue marked as Moderate?
Most modern screen readers default to the user’s language when codes conflict, so content remains somewhat usable. However, pronunciation, hyphenation, and dictionary support are often wrong, which slows comprehension and increases cognitive load, especially for multilingual users, so the impact is more than minor but short of severe.
Standards and Regulations
| Standard | Success Criterion | Reference |
|---|---|---|
| WCAG 2.2 | 3.1.1 Language of Page (A) | The default human language of each web page can be programmatically determined. |
| EN 301 549 | 9.3.1.1 Language of Page | Same as the WCAG text. |