# HTML XML Lang Mismatch

> If the <html> tag has lang and xml:lang attributes, both attributes must carry the same valid language code.

Source: https://knowledge.evinced.com/web/web-validations/html-xml-lang-mismatch

If the `<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](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes) list.

```html
<!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.

```html
<!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

1.  Open the page in a browser.
2.  Open Developer Tools and switch to the Elements panel.
3.  Select the root `<html>` element and look at the `lang` and `xml:lang` attributes.

**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](https://www.w3.org/TR/WCAG22/#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](https://www.etsi.org/standards/etsi-301-549) | Same as the WCAG text. |

## Personas impacted by this issue

-   [Screen Reader](https://knowledge.evinced.com/a11y-essentials/personas#screen-reader)
-   [Braille](https://knowledge.evinced.com/a11y-essentials/personas#braille)
-   [Voice Input](https://knowledge.evinced.com/a11y-essentials/personas#voice-input)

## Related Issues

-   [html-lang-valid](https://knowledge.evinced.com/web/web-validations/html-lang-valid)
-   [valid-lang](https://knowledge.evinced.com/web/web-validations/valid-lang)
-   [html-has-lang](https://knowledge.evinced.com/web/web-validations/html-has-lang)
-   [language-attribute-mismatch](https://knowledge.evinced.com/web/web-validations/language-attribute-mismatch)
