Skip to content

lang and xml:lang name different languages

a11y-lang-mismatchmoderate
On this page

Why it matters

  • A screen reader reads a page with the voice and pronunciation of its language. An Arabic page read with an English voice is hard to follow, and the reverse too.
  • xml:lang is a leftover of XHTML. When it is there with a different language than lang, software that reads one or the other disagrees about the page.
  • WCAG 2.2 asks that the page's language can be determined by software (success criterion 3.1.1, level A).

Example

Wrong
<html lang="ar" xml:lang="en" dir="rtl">
Right
<html lang="ar" xml:lang="ar" dir="rtl">

How to fix

Give both the same language, or remove xml:lang, which an HTML page does not need:

html
<html lang="ar" xml:lang="ar" dir="rtl">

How we detect

  1. We render the page and run axe-core 4.13.0's html-xml-lang-mismatch rule in each engine.
  2. It applies when <html> has both attributes with valid values, and reports when their primary languages differ (ar and ar-SA agree).