Invalid language code on part of the page
language/part-invalid
- WCAG success criterion
- 3.1.2 (level AA)
- Outcome class
- Automatic. An automated check that can report a confirmed violation.
- Area
- Accessibility, Language & Clarity
- Default severity
- medium
- axe-core rule
language/part-invalid
Why we flag this
Screen readers cannot switch to the right pronunciation for that passage.
lang below <html> that is not a valid BCP 47 tag and sets the language of text.
What the rule checks
Scope. Elements below html with a non-empty lang attribute whose own text (text nodes or a non-empty img alt not claimed by an inner lang) is rendered.
Expectation. Fails when the lang attribute of such an element is not a valid BCP 47 tag (primary subtag not a language: "dutch", "english", "invalid"): the passage gets no language, so assistive technology cannot pick the pronunciation 3.1.2 asks for. Reported once, at the element carrying the attribute. Only the primary subtag has to be valid ("en-US-GB" passes). Text inside an inner element with its own lang belongs to that lang; an image carries text through a non-empty alt. Text hidden from the accessibility tree (aria-hidden) is still drawn and counts; text that is not rendered does not. lang="" states that the language is unknown and is not a finding; the root element is document/lang-invalid, not this id.
Source. WCAG 2.2 SC 3.1.2 Language of Parts; H58; BCP 47 (RFC 5646) primary language subtag; ACT de46e4
Detection: shared; needs dom, computed_style.
Failing example
The check reports a violation here. Corpus case language_part_invalid, element p#quote-dutch. The page may contain further findings for other rules.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quotes from the trip - Travel journal</title>
<style>
body { color: #111111; background: #ffffff; font-size: 16px; }
</style>
</head>
<body>
<header>
<a href="#main" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Skip to main content</a>
<p>Travel journal</p>
<nav aria-label="Main"><a href="#main" aria-current="page" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Overview</a></nav>
</header>
<main id="main">
<h1>Quotes from the trip</h1>
<!-- "dutch" is not a BCP 47 primary language subtag (WCAG 3.1.2, H58). -->
<p id="quote-dutch" lang="dutch">Zij liepen een vreemde Tiki bar binnen.</p>
<!-- The text is still drawn although it is hidden from the accessibility
tree; its language is still undetermined. -->
<div id="quote-hidden" lang="english"><p aria-hidden="true">They wandered into a strange Tiki bar.</p></div>
<!-- An image carries text through its alt; the alt gets no language. -->
<div id="photo" lang="invalid"><img src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" alt="Fireworks over the harbour" width="200" height="100"></div>
</main>
<footer><p>Footer text</p></footer>
</body>
</html>Passing example
The check passes here and reports nothing. Corpus case language_part_valid. The page may contain further findings for other rules.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Quotes from the trip - Travel journal</title>
<style>
body { color: #111111; background: #ffffff; font-size: 16px; }
</style>
</head>
<body>
<header>
<a href="#main" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Skip to main content</a>
<p>Travel journal</p>
<nav aria-label="Main"><a href="#main" aria-current="page" style="display: inline-block; min-width: 44px; min-height: 44px; line-height: 44px; padding: 0 8px">Overview</a></nav>
</header>
<main id="main">
<h1>Quotes from the trip</h1>
<!-- Only the primary subtag has to be a known language (BCP 47). -->
<p id="quote-region" lang="en-US-GB">They wandered into a strange Tiki bar.</p>
<p id="quote-de" lang="de">Sie betraten eine seltsame Tiki-Bar und bestellten zwei Getränke.</p>
<!-- The invalid code determines no text: the inner lang takes it. -->
<div id="nested" lang="invalid"><p lang="en">They ordered two drinks and sat down by the window.</p></div>
</main>
<footer><p>Footer text</p></footer>
</body>
</html>This page is generated from the rule catalogue and the rule contracts; see therule overview for how the outcome classes are derived.