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.
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
- Add
langto the<html>element in your base template or document component. - Use the active locale when the site is multilingual.
- Re-run axe to confirm the rule passes.
<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.
// 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.