Skip to main content
🎉 A11y Issue Detection Agent is now live! Detect accessibility issues like a WCAG expert with AI. Try now!
No Result Found
Connect and get help from 7,000+ developers on our Discord community. Ask the CommunityAsk the Community

html-xml-lang-mismatch

Severity: Moderate

Description

When both the lang and xml:lang attributes are present on the <html> element, they must specify the same primary language. The xml:lang attribute is used in XHTML documents while lang is used in HTML. If they specify different languages, screen readers that process both attributes may encounter conflicting instructions about how to pronounce the page content.

Example

In the following example, lang is set to "en" (English) while xml:lang is set to "fr" (French). Screen readers may use one value or the other, leading to incorrect pronunciation of the page content. This breaks the html-xml-lang-mismatch rule.

Incorrect sample - lang and xml:lang mismatch
Copy icon Copy

In contrast, the following code snippet sets both lang and xml:lang to the same value "en". Both attributes agree on the page language, and the code does not break the html-xml-lang-mismatch rule.

Correct sample - matching lang and xml:lang
Copy icon Copy

How to fix?

Check if your <html> element has both lang and xml:lang attributes. If so:

  • Ensure both attributes use the same primary language subtag (for example, both set to "en" or both set to "fr").
  • For HTML5 documents that are not served as XHTML, you can safely remove the xml:lang attribute and keep only lang.

Reference

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle