The <html> lang attribute must be a valid language code
The lang attribute on the html element must contain a valid language code, such as en or es-MX, so assistive technology can recognize the page language.
| Rule ID | html-lang-valid |
|---|---|
| Impact | Serious |
| Success criterion | 3.1.1 Language of Page · A |
| Standards | WCAG 2.0 · WCAG 2.1 · WCAG 2.2 · Section 508 · EN 301 549 |
| Fixed automatically |
Example
<!DOCTYPE html>
<html lang="english">
<head><title>Track your order</title></head>
</html>The screen reader does not recognize "english" and reads the page in the user's default voice.
<!DOCTYPE html>
<html lang="en">
<head><title>Track your order</title></head>
</html>The screen reader recognizes English and pronounces the page correctly.
Why it matters
A lang value only helps if software understands it. Screen readers, braille displays and text-to-speech tools look for a standard language code. A value like english, en_US or a typo such as eng-us is ignored, and the page is read with the user's default voice and pronunciation, often making it hard to follow.
The same applies to browsers choosing fonts, hyphenation and translation offers, and to search engines working out which audience the page serves. An invalid code is as bad as no code at all, and it is easy to miss because nothing looks wrong on screen.
How to fix it
Use a language tag made of a two- or three-letter ISO 639 language code, optionally followed by a hyphen and a region or script:
<html lang="en"> <!-- English -->
<html lang="en-US"> <!-- English, United States -->
<html lang="zh-Hant"> <!-- Chinese, traditional script -->
Common mistakes to fix:
- Language names:
english,Deutsch→en,de - Underscores from server locales:
en_US,fr_CA→en-US,fr-CA - Country codes instead of language codes:
jp→ja,cz→cs,dk→da. Note thatukmeans Ukrainian; British English isen-GB. - Template placeholders left empty or unrendered:
lang="{{ locale }}".
Locale from the server. If your framework gives a locale like en_US, convert it before printing:
<html lang="<?= str_replace('_', '-', $locale) ?>">
The region part is optional. When in doubt, the plain language code is always valid.
Checklist
- Use an ISO language code, not a language name.
- Use hyphens, not underscores, before the region.
- Do not use country codes like jp, cz or dk.
- Check templates print the value, not a placeholder.
How the check works
The check reads the lang (and xml:lang, if present) value of the <html> element and fails when its primary part, before the first hyphen, is not a known language code. Region and script parts are not validated in detail. It does not tell you whether the code matches the language of the content: confirm that manually.
Resources
- Understanding 3.1.1 Language of Page W3C
- W3C ACT rule bf051a W3C ACT
- Declaring language in HTML W3C i18n
Updated October 27, 2026