Language Rule

lang and xml:lang must name the same language html-xml-lang-mismatch

Some pages, usually ones generated as XHTML or from older templates, carry both a lang attribute and an xml:lang attribute on the html element. Browsers read lang; XML tools read xml:lang. If they disagree, different software picks a different language for the same page. The check compares the base language of each: en and en-GB agree, en and fr do not.

Websight reports this as HTML elements with lang and xml:lang must have the same base language

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.

Broken
<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.

Fixed
<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

  1. View the page source and look at the html element. If it has both lang and xml:lang, compare the part before any hyphen.
  2. Check the generated source, not just your template; some content systems add xml:lang on their own.
  3. If the page is served as text/html (almost all are), remove xml:lang and keep lang.

The fix

Before
<html lang="en" xml:lang="fr">
After
<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

Before
<html lang="en" xml:lang="fr">
After
<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:

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.

Scan your own page for this and 63 other checks

Open any page in Chrome, click Websight, and get a score out of 100 with every issue explained and a draft fix snippet per element.

Add Websight to Chrome

Free scans, no account, nothing leaves your computer. Automated tools find only part of the problems; the extension says so on every report.