Who it affects
Someone using a screen reader on the parish council's archived minutes hears English read in a French voice, because their software took its cue from the attribute the template author forgot to update.
Someone running the page through a translation or text-to-speech service that reads xml:lang gets a translation from French that makes no sense.
The council's web volunteer changed lang when the site moved from a French host's template and never knew xml:lang existed.
Broken versus fixed
The broken markup is shown as code rather than rendered, because the effect is in how it is announced or handled, not how it looks.
<html lang="en" xml:lang="fr" xmlns="http://www.w3.org/1999/xhtml">
The two attributes disagree. Whichever one a piece of software reads, half the time it gets the wrong language.
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
Both say English. Better still, if the page is served as ordinary HTML, drop xml:lang altogether.
Test it by hand in two minutes
- View the page source and look at the html element. If it has both lang and xml:lang, compare the part before any hyphen.
- Check the generated source, not just your template; some content systems add xml:lang on their own.
- If the page is served as text/html (almost all are), remove xml:lang and keep lang.
The fix
<html lang="en" xml:lang="fr">
<html lang="en" xml:lang="en">
Match the base language. en-GB and en-US count as the same language for this check.
Drop xml:lang
<html lang="en" xml:lang="fr">
<html lang="en">
Only XHTML served as application/xhtml+xml needs xml:lang. For everything else it is noise.
Common mistakes
- Updating lang in the template but leaving xml:lang in a separate header include.
- Setting xml:lang from the site's default language and lang from the page's, so every translated page mismatches.
- Adding xml:lang to plain HTML because a validator once suggested it.
WCAG criteria this rule maps to
axe-core tags this rule as WCAG 2.2 level A. It is one of the checks for:
- 3.1.1 Language of Page (level A). Official W3C text.
The scanner compares the primary language subtags of lang and xml:lang on the html element. It only runs when both are present and valid, and it does not look at the page text. Automated tools find only part of the accessibility problems on a page; a pass on this rule is not a pass on the criterion.
Related rules
html-has-lang
The lang attribute on the html element tells browsers and screen readers which language the page is written in.
A
The page language code must be valid
html-lang-valid
A lang attribute only works if its value is a real language tag: a two or three letter code like en, cy or fr, optionally followed by a hyphen and a region, like en-GB.
AA
Language codes on page sections must be valid
valid-lang
When part of a page is in a different language from the rest, put a lang attribute on that element.