Skip to content
Latchkey

axe-core "html-has-lang" <html> element must have a lang attribute in CI

axe-core rule html-has-lang found the <html> element without a lang attribute. WCAG 3.1.1 requires a page language so screen readers pronounce content correctly. The related html-lang-valid rule fails on an invalid value.

What this error means

axe reports "html-has-lang: <html> element must have a lang attribute" against the document root, typically on a page rendered from a template that omits lang.

axe-core
html-has-lang: <html> element must have a lang attribute (serious)
  Fix any of the following:
    The <html> element does not have a lang attribute
  <html>

Common causes

The document template omits lang on <html>

The base HTML shell or framework document component renders <html> with no lang, so every page inherits the violation.

A dynamic locale is not written to the attribute

The site supports multiple languages but the current locale is never applied to the <html lang> attribute at render time.

How to fix it

Set lang on the document root

  1. Add lang to the <html> element in your base template or document component.
  2. Use the active locale when the site is multilingual.
  3. Re-run axe to confirm the rule passes.
index.html
<html lang="en">

Drive lang from the current locale

In a framework document component, write the resolved locale into the attribute so it stays valid across languages.

_document.jsx
// Next.js
export default function Document({ locale }) {
  return <Html lang={locale ?? 'en'}> ... </Html>;
}

How to prevent it

  • Set a valid lang on <html> in the base template.
  • Drive lang from the active locale for multilingual sites.
  • Run axe on a full page render, not only isolated components.

Frequently asked questions

What causes ""html-has-lang" (missing lang attribute)"?
The base HTML shell or framework document component renders <html> with no lang, so every page inherits the violation.
How do I fix "html-has-lang" (missing lang attribute)?
Set lang on the document root

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card