How to fix "html element must have a lang attribute"
Screen readers switch voices by language. Without a declared language, a French page may be read with English pronunciation rules, which makes it close to unintelligible. This fails WCAG 3.1.1 and it is a one-line fix.
<html lang="en">
Use the code for the language the page is actually written in: en, es, fr, de, pt-BR and so on.
In templates
- Shopify:
<html lang="{{ request.locale.iso_code }}"> - WordPress:
<html <?php language_attributes(); ?>> - Next.js (App Router): set it on the
htmlelement inapp/layout. - Hugo:
<html lang="{{ site.Language.Lang }}">
Passages in another language
Mark a quotation or phrase in a different language on its own element, which satisfies WCAG 3.1.2:
<p>Our motto is <span lang="fr">joie de vivre</span>.</p>
An empty value (lang="") or an invalid code fails the same way as a missing attribute.
Check your own site
Our free scanner loads your pages in a real browser and lists every failure like this one that automated testing can detect. Scan a site.