lang and xml:lang on <html> must name the same language

If the html element has both lang and xml:lang, both must name the same base language, so every tool reads the page in the same, correct language.

Rule IDhtml-xml-lang-mismatch
ImpactModerate
Success criterion 3.1.1 Language of Page · A
StandardsWCAG 2.0 · WCAG 2.1 · WCAG 2.2 · Section 508 · EN 301 549
Readabler fix Fixed automatically

Example

Before
<!DOCTYPE html>
<html lang="en" xml:lang="de">
  <head><title>Hotel booking</title></head>
</html>

Depending on the software, the English page may be read with a German voice.

After
<!DOCTYPE html>
<html lang="en" xml:lang="en">
  <head><title>Hotel booking</title></head>
</html>

Every screen reader and browser agrees the page is in English.

Why it matters

Some tools read lang, others read xml:lang, and which one wins depends on the browser, the document type and the assistive technology. When they disagree, a screen reader user may hear the page in the wrong voice and pronunciation, and a braille display may use the wrong contraction tables. The problem appears only for some people, which makes it hard to notice.

A mismatch usually comes from a template where one attribute was updated and the other was forgotten, for example after translating a site.

How to fix it

Make both attributes name the same language. A different region is fine (en-US and en-GB share the base language en), but the language itself must match.

<html lang="fr-CA" xml:lang="fr-CA">

Drop xml:lang if you can. Pages served as text/html do not need it: the HTML parser ignores it, and lang is enough:

<html lang="fr-CA">

Keep xml:lang only for documents served as XHTML (application/xhtml+xml), and then set both from the same variable in your template so they cannot drift apart:

<html xmlns="http://www.w3.org/1999/xhtml" lang="{{ locale }}" xml:lang="{{ locale }}">

Translated sites. Check every language version: the mismatch often shows up only on pages where the translation plugin changed one attribute.

Also check that the language you keep is the real language of the content.

Checklist

  1. Make lang and xml:lang name the same language.
  2. Remove xml:lang from pages served as HTML.
  3. Set both from one template variable in XHTML.
  4. Check every language version of the site.

How the check works

The check applies to an <html> element that has both a valid lang and a valid xml:lang. It compares their primary language parts (the code before the first hyphen) and fails when they differ. en-US and en-GB pass. Pages with only one of the attributes are not tested by this check.

Resources

Updated October 27, 2026