Declare your page's language so screen readers pronounce it right

<html> element must have a lang attribute is the message for axe's html-has-lang rule, and it means the opening html tag doesn't say what language the page is written in. Without it, a screen reader falls back to the language its user chose as a default and reads your text with that language's pronunciation. Add the attribute to the html element, such as lang="en" for English, in the template or layout that renders it.

Why the page language matters to a screen reader

  • Screen readers use a separate set of pronunciation rules for each language and switch between them only when the page says which language it's in. Deque's rule page explains that without a declared language, the screen reader reads the page in its user's default language, which can make the text impossible to follow.

  • WCAG's Language of Page criterion, at Level A, asks that software can determine each page's default language. W3C adds that browsers and other tools render text more accurately when they know it.

What to put in the lang attribute

PageMarkup
An English page<html lang="en">
A British English page, where the spelling matters<html lang="en-GB">
A Canadian French page<html lang="fr-CA">
An Arabic page, written right to left<html lang="ar" dir="rtl">
A Spanish quote inside an English pageThe page keeps lang="en", and the quote gets <span lang="es">
A page that uses two languagesThe one used most. W3C's guidance picks the most-used language as the default, or the first one used when they're even.

Why the rule fails when a language seems set

  • Only xml:lang is present

    On a page served as HTML, axe wants the lang attribute itself. Its message for this case says xml:lang isn't valid on HTML pages and to use lang.

  • The attribute is on the wrong element

    A lang on body or on a wrapper div doesn't count. The rule reads only the html element at the top of the document.

  • A framework renders the html tag elsewhere

    Single-page apps and static site generators usually render the html element from one root layout or index file. A lang set inside a page component doesn't reach it.

  • An empty or misspelled value

    An empty lang fails this rule. A value that isn't a known language code fails a separate rule, html-lang-valid, which checks it against a list of valid languages.

The messages are in axe-core's message list. W3C's language declaration guide says lang values follow BCP 47, with codes in the IANA Language Subtag Registry.

How to add the lang attribute

  1. Find where the html tag is renderedIn a hand-written site, that's the top of each HTML file. In a framework or CMS, look in the root layout, the document template or the theme's header file.
  2. Set the main languageAdd lang with the code for the language most of the page is written in, such as en, de or ja.
  3. Mark passages in other languagesWrap a quote or phrase in another language in an element with its own lang, so the screen reader switches only for that part.
  4. Give translations their own valueEach translated version of a page needs its own language in the html tag, not the default copied from the main template.
  5. Rerun the rule on each templateRun axe on one page from every layout your site uses, since a page built from a different template can still be missing the attribute.

Frequently asked questions

Should I use en or en-US?

Either one passes. W3C's advice on choosing a tag is to keep it as short as possible and add a region only when it carries information you need, such as en-GB where British spelling matters for spell-checking.

Does Google use the lang attribute?

Not to work out a page's language. Google's multilingual guide says it uses the visible content of the page and ignores code-level language information such as lang. Set it for screen readers and browsers; for search, use hreflang to link translations.

How many sites leave out the page language?

WebAIM's 2026 Million report lists a missing document language among the six most common failures, found on 13.5% of the top million home pages.