Skip to main content
HTML Validation

When the attribute “xml:lang” in no namespace is specified, the element must also have the attribute “lang” present with the same value.

About This HTML Issue

The xml:lang attribute is a holdover from XHTML, where it was the standard way to declare the language of an element. In HTML5 (the text/html serialization), the lang attribute is the proper way to specify language. The HTML specification allows xml:lang for compatibility purposes, but only if it is accompanied by a lang attribute with an identical value. If xml:lang appears alone, or if its value doesn’t match the lang attribute, the document is non-conforming.

This matters for several reasons. Screen readers and other assistive technologies rely on the lang attribute—not xml:lang—to determine pronunciation and language-specific behavior. Search engines also use lang for content indexing and language detection. Having xml:lang without lang means the language declaration may be ignored entirely, degrading both accessibility and SEO.

In modern HTML5 documents, there is rarely a reason to include xml:lang at all. The lang attribute alone covers all use cases. The only scenario where you might need both is if your document must be compatible with both HTML and XHTML parsers (polyglot markup), in which case the two attributes must carry the same value.

How to Fix

You have two options:

  1. Remove xml:lang and use only lang (recommended for HTML5 documents).
  2. Add a lang attribute that matches the existing xml:lang value (for polyglot documents).

If you do keep both attributes, make sure the values are exactly the same—including case and subtags. For example, lang="en-US" must be paired with xml:lang="en-US", not xml:lang="en".

Examples

Incorrect: xml:lang without lang

<html xml:lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p xml:lang="fr">Bonjour le monde</p>
  </body>
</html>

This triggers the validation error because both the <html> and <p> elements have xml:lang but no lang attribute.

Incorrect: Mismatched values

<html lang="en" xml:lang="en-US">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p>Hello world</p>
  </body>
</html>

Even though both attributes are present, the values "en" and "en-US" don’t match, which is also invalid.

Correct: Using only lang (recommended)

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p lang="fr">Bonjour le monde</p>
  </body>
</html>

This is the cleanest approach for HTML5 documents. The lang attribute is all you need.

Correct: Both attributes with matching values (polyglot)

<!DOCTYPE html>
<html lang="en" xml:lang="en">
  <head>
    <title>My Page</title>
  </head>
  <body>
    <p lang="fr" xml:lang="fr">Bonjour le monde</p>
  </body>
</html>

If you must keep xml:lang, every element that has it must also have lang with the exact same value.

Find issues like this automatically

Rocket Validator scans thousands of pages in seconds, detecting HTML issues across your entire site.

Help us improve our guides

Was this guide helpful?

Ready to validate your sites?
Start your trial today.