Element with lang attribute has valid language tag

  • Rule Type:atomic
  • Rule Id: de46e4
  • Last modified: Jul 07, 2020
  • Accessibility Requirements Mapping:
    • 3.1.2 Language of Parts (Level: AA)
      • Learn More about 3.1.2 (Language of Parts)
      • Required for conformance to WCAG 2.0 and above on level AA and above.
      • Outcome mapping:
        • Any failed outcomes: success criterion is not satisfied.
        • All passed outcomes: success criterion needs further testing.
        • An inapplicable outcome: success criterion needs further testing.
    • H58: Using language attributes to identify changes in the human language
  • Input Aspects:

Description

This rule checks that a non-empty lang attribute of an element in the page body has a language tag with a known primary language subtag.

Applicability

This rules applies to any HTML element that:

Expectation

For each test target, the value of the lang attribute is a valid language tag.

Assumptions

  • The lang attribute is assumed to be used to indicate the language of a section of the content. If the lang attribute is used for something else (for example to indicate a code element contains CSS), the content may still conform to WCAG despite failing this rule.
  • This rule assumes that user agents and assistive technologies can programmatically determine valid language tags even if these do not conform to the BCP 47 syntax.
  • This rule assumes that grandfathered tags are not used as these will not be recognized as valid language tags.
  • The language of the page can be set by other methods than the lang attribute, for example using HTTP headers or the meta element. These methods are not supported by all assistive technologies. This rule assumes that these other methods are insufficient to satisfying Success Criterion 3.1.1: Language of Page.

Accessibility Support

There are differences in how assistive technologies handle unknown and invalid language tags. Some will default to the language of the page, whereas others will default to the closest ancestor with a valid lang attribute.

Background

Test Cases

Passed

Passed Example 1

Open in a new tab

The lang attribute has a value that is not empty ("") and has a valid language tag.

<html>
	<body>
		<article lang="en"></article>
	</body>
</html>

Passed Example 2

Open in a new tab

The lang attribute has a value that is not empty ("") and has a valid language tag. The region section in the value is ignored by the rule.

<html>
	<body>
		<blockquote lang="fr-CH"></blockquote>
	</body>
</html>

Passed Example 3

Open in a new tab

The lang attribute value has a valid language tag, but a syntactically invalid region subtag.

<html>
	<body>
		<p lang="en-US-GB"></p>
	</body>
</html>

Failed

Failed Example 1

Open in a new tab

The lang attribute value is not a primary language subtag.

<html>
	<body>
		<article lang="dutch"></article>
	</body>
</html>

Failed Example 2

Open in a new tab

The lang attribute value is not empty ("") and is not a primary language subtag.

<html>
	<body>
		<article lang="#!"></article>
	</body>
</html>

Failed Example 3

Open in a new tab

The lang attribute value consists of only ASCII whitespace and is not a valid language tag.

<html>
	<body>
		<article lang=" ">
			The quick brown fox jumped over the lazy dog
		</article>
	</body>
</html>

Inapplicable

Inapplicable Example 1

Open in a new tab

The rule applies to elements within the body of a webpage. html elements are ignored by the rule.

<html lang="en">
	<body></body>
</html>

Inapplicable Example 2

Open in a new tab

An empty value for the lang attribute is ignored, as the rule only applies to lang attributes that are not empty ("").

<html>
	<body>
		<article lang=""></article>
	</body>
</html>

Glossary

Outcome

An outcome is a conclusion that comes from evaluating an ACT Rule on a test subject or one of its constituent test target. An outcome can be one of the three following types:

  • Inapplicable: No part of the test subject matches the applicability
  • Passed: A test target meets all expectations
  • Failed: A test target does not meet all expectations

Note: A rule has one passed or failed outcome for every test target. When there are no test targets the rule has one inapplicable outcome. This means that each test subject will have one or more outcomes.

Note: Implementations using the EARL10-Schema can express the outcome with the outcome property. In addition to passed, failed and inapplicable, EARL 1.0 also defined an incomplete outcome. While this cannot be the outcome of an ACT Rule when applied in its entirety, it often happens that rules are only partially evaluated. For example, when applicability was automated, but the expectations have to be evaluated manually. Such "interim" results can be expressed with the incomplete outcome.

Valid Language Tag

A language tag is valid if its primary language subtag exists in the language subtag registry with a Type field whose field-body value is language.

A "language tag" is here to be understood as in the first paragraph of the BCP 47 language tag syntax, i.e. a sequence of subtags separated by hyphens, where a subtag is any sequence of alphanumerical characters. Thus, this definition intentionally differs from the strict BCP 47 syntax (and ABNF grammar) as user agents and assistive technologies are more lenient in what they accept. The definition is however consistent with the behavior of the :lang() pseudo-selector as defined by Selectors Level 3. For example, de-hello would be an accepted way to indicate German in current user agents and assistive technologies, despite not being valid according to BCP 47 grammar. As a consequence of this definition, however, grandfathered tags are not correctly recognized as valid language subtags.

Subtags, notably the primary language subtag, are case insensitive. Hence comparison with the language subtag registry must be done in a case insensitive way.


Useful Links


Implementations

This section is not part of the official rule. It is populated dynamically and not accounted for in the change history or the last modified date. This section will not be included in the rule when it is published on the W3C website.

ToolConsitencyCompleteReport
AlfaconsistentYesView Report
QualWebconsistentYesView Report
SortSiteconsistentYesView Report
axe-corepartially-consistentYesView Report

Acknowledgments

Table of Contents