Skip to content

Language changes need valid language tags

  • Rule: axe/valid-lang
  • Checks: lang attribute must have a valid value
  • WCAG: 3.1.2
  • Fix class: content: A fix needs authored text.
  • People who use a screen reader or a braille display, most of them blind.
  • People with cognitive, learning or attention disabilities.

A lang value is a language name or a country code, such as lang="french" or lang="jp"

Section titled “A lang value is a language name or a country code, such as lang="french" or lang="jp"”

Use the BCP 47 tag of the language the text is in, such as fr or ja.

<p>The Spanish greeting <span lang="es">buenos días</span> is used until noon.</p>

A language switcher marks each language name with an invalid tag

Section titled “A language switcher marks each language name with an invalid tag”

Mark each link with the tag of the language its text is in, so that screen readers say each name correctly.

<p>
This page is also in <a href="/de/" lang="de">Deutsch</a> and
<a href="/ja/" lang="ja">日本語</a>.
</p>

The value is only spaces, or a placeholder a template never filled

Section titled “The value is only spaces, or a placeholder a template never filled”

Write the text’s language tag where the template renders lang, or remove the attribute when the text is in the language it would inherit from the nearest ancestor with lang.

Removing an invalid lang from text in another language instead of correcting it

Section titled “Removing an invalid lang from text in another language instead of correcting it”

axe stops reporting it, but screen readers then read that text with the surrounding language’s pronunciation.

axe-core’s documentation of the rule

CORA’s fix guidance adapts content from accessibility-agents, under the MIT License: see its notice.