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 IDhtml-lang-valid
ImpactSerious
Success criterion 3.1.1 Language of Page · A
StandardsWCAG 2.0 · WCAG 2.1 · WCAG 2.2 · Section 508 · EN 301 549
Readabler fix Fixed automatically

Example

Before
<!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.

After
<!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 that uk means Ukrainian; British English is en-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

  1. Use an ISO language code, not a language name.
  2. Use hyphens, not underscores, before the region.
  3. Do not use country codes like jp, cz or dk.
  4. 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

Updated October 27, 2026