Skip to content
English
  • There are no suggestions because the search field is empty.

A: HTML elements with lang and xml -> lang must have the same base language (WCAG 3.1.1)

html-xml-lang-mismatch

Ensure that HTML elements with valid lang and xml:lang attributes carry the same language declaration.

This means

If an element has both lang and xml:lang attributes, their values must match (the same BCP-47 language code, including optional region). Differences such as lang="de" and xml:lang="en" or lang="de" and xml:lang="de-AT" are considered contradictory.

Impact

Assistive technologies may select incorrect voices, pronunciation and hyphenation become inconsistent. Users lose orientation; additionally, this may lead to a WCAG violation.

Recommendation

  • Prefer using only lang in HTML5.

  • Use xml:lang only when the document is delivered as XML (for example XHTML application/xhtml+xml) or within SVG/MathML.

  • If both attributes are necessary: set identical values (including region).

  • Use valid BCP-47 codes (dede-DEen-GB); use hyphens, not underscores.

  • When dynamically changing languages, update both attributes consistently.

Example

Problematic

<!-- Contradiction: German vs. English -->
<html lang="de" xml:lang="en">
  <head><title>Contact</title></head>
  <body>Welcome</body>
</html>
 
<!-- Contradiction: base vs. region -->
<p lang="fr" xml:lang="fr-CA">Bonjour</p>

Better

<!-- HTML5: use only lang -->
<html lang="de">
  <head><meta charset="utf-8"><title>Contact</title></head>
  <body>Welcome</body>
</html>
 
<!-- If both are needed: identical values -->
<html lang="de-DE" xml:lang="de-DE"></html>
 
<!-- Remain consistent in embedded SVG -->
<svg lang="en-US" xml:lang="en-US" role="img" aria-label="Logo"></svg>

Related WCAG criterion:
WCAG 3.1.1 - Language of Page