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:langis a leftover of XHTML. When it is there with a different language thanlang, 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
<html lang="ar" xml:lang="en" dir="rtl">
<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
- We render the page and run axe-core 4.13.0's
html-xml-lang-mismatchrule in each engine. - It applies when
<html>has both attributes with valid values, and reports when their primary languages differ (arandar-SAagree).