Element with lang attribute has valid language tag

  • Rule Type:atomic
  • Rule Id: de46e4
  • Last modified: Feb 14, 2022
  • 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 later on level AA and higher.
      • 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
      • Learn More about technique H58
      • Not required to conformance to any W3C accessibility recommendation.
      • Outcome mapping:
        • Any failed outcomes: technique is not satisfied.
        • All passed outcomes: technique needs further testing.
        • An inapplicable outcome: technique needs further testing.

Description

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

Applicability

This rule applies to any HTML element with a lang attribute value that is not empty ("") and for which all of the following is true:

Expectation

For each test target, the lang attribute value has a known primary language tag.

Assumptions

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

Bibliography

Test Cases

Passed

Passed Example 1

Open in a new tab

This article element has a lang attribute value which has a known primary language tag.

<html>
	<body>
		<article lang="en">
			They wandered into a strange Tiki bar on the edge of the small beach town.
		</article>
	</body>
</html>

Passed Example 2

Open in a new tab

This blockquote element has a lang attribute value which has a known primary language tag. The region section ("CH") in the value is ignored by the rule (and the definition of known primary language tag).

<html>
	<body>
		<blockquote lang="fr-CH">
			Ils ont trouvé un étrange bar Tiki aux abords de la petite ville balnéaire.
		</blockquote>
	</body>
</html>

Passed Example 3

Open in a new tab

This p element has a lang attribute value which has a known primary language tag, but a syntactically invalid region subtag which is ignored by the rule.

<html>
	<body>
		<p lang="en-US-GB">
			They wandered into a strange Tiki bar on the edge of the small beach town.
		</p>
	</body>
</html>

Passed Example 4

Open in a new tab

This div element has a valid lang attribute value. There is no text inheriting its programmatic language from the article element, therefore its lang attribute is not considered by the rule.

<html>
	<body>
		<article lang="invalid">
			<div lang="en">
				They wandered into a strange Tiki bar on the edge of the small beach town.
			</div>
		</article>
	</body>
</html>

Passed Example 5

Open in a new tab

This div element has a valid lang attribute value. The accessible name of the image is text inheriting its programmatic language from the div element.

<html>
	<body>
		<div lang="EN">
			<img src="/test-assets/shared/fireworks.jpg" alt="Fireworks over Paris" />
		</div>
	</body>
</html>

Failed

Failed Example 1

Open in a new tab

This article element has a lang attribute value which does not have a known primary language tag because its primary language subtag does not exist in the language subtag registry.

<html>
	<body>
		<article lang="dutch">
			Zij liepen een vreemde Tiki bar binnen, aan de rand van een dorpje aan het strand.
		</article>
	</body>
</html>

Failed Example 2

Open in a new tab

This article element has a lang attribute value which has no known primary language tag.

<html>
	<body>
		<article lang="#!">
			They wandered into a strange Tiki bar on the edge of the small beach town.
		</article>
	</body>
</html>

Failed Example 3

Open in a new tab

This article element has a lang attribute value which consists of only whitespace and thus has no known primary language tag.

<html>
	<body>
		<article lang="  ">
			They wandered into a strange Tiki bar on the edge of the small beach town.
		</article>
	</body>
</html>

Failed Example 4

Open in a new tab

The lang attribute value does not have a valid language tag. The lang attribute must be valid because the content is visible.

<html>
	<body>
		<article lang="english">
			<p aria-hidden="true">
				They wandered into a strange Tiki bar on the edge of the small beach town.
			</p>
		</article>
	</body>
</html>

Failed Example 5

Open in a new tab

The lang attribute value does not have a valid language tag, and its descendant is not visible though it is still included in the accessibility tree.

<html>
	<body>
		<article lang="English">
			<p style="position: absolute; top: -9999px">
				They wandered into a strange Tiki bar on the edge of the small beach town.
			</p>
		</article>
	</body>
</html>

Failed Example 6

Open in a new tab

This div element has an invalid lang attribute value. There is no text inheriting its programmatic language from the article element, therefore its lang attribute is not considered by the rule.

<html>
	<body>
		<article lang="en">
			<div lang="invalid">
				They wandered into a strange Tiki bar on the edge of the small beach town.
			</div>
		</article>
	</body>
</html>

Failed Example 7

Open in a new tab

This div element has an invalid lang attribute value. The accessible name of the image is text inheriting its programmatic language from the div element.

<html>
	<body>
		<div lang="invalid">
			<img src="/test-assets/shared/fireworks.jpg" alt="Fireworks over Paris" />
		</div>
	</body>
</html>

Failed Example 8

Open in a new tab

The lang attribute value of this p element is an iso 639.2 three letters code, which has no known primary language tag.

<html lang="en">
	<body>
		<p lang="eng">I love ACT rules!</p>
	</body>
</html>

Failed Example 9

Open in a new tab

The lang attribute value of this p element is a grandfathered tag, which has no known primary language tag.

<html lang="lb">
	<body>
		<p lang="i-lux">Lëtzebuerg ass e Land an Europa.</p>
	</body>
</html>

Inapplicable

Inapplicable Example 1

Open in a new tab

There is no element with a lang attribute value which is a descendant of a body element.

<html lang="en">
	<body>
		They wandered into a strange Tiki bar on the edge of the small beach town.
	</body>
</html>

Inapplicable Example 2

Open in a new tab

There is no element which is a descendant of a body element and has a non-empty lang attribute value.

<html lang="en">
	<body>
		<article lang="">
			They wandered into a strange Tiki bar on the edge of the small beach town.
		</article>
	</body>
</html>

Inapplicable Example 3

Open in a new tab

There is no element with a text node as a descendant in the flat tree that is either visible or included in the accessibility tree.

<html lang="en">
	<body>
		<p lang="hidden">
			<span style="display: none;">
				They wandered into a strange Tiki bar on the edge of the small beach town.
			</span>
		</p>
	</body>
</html>

Inapplicable Example 4

Open in a new tab

There is no text inheriting its programmatic language from this div element.

<html lang="en">
	<body>
		<div lang="invalid">
			<img src="/test-assets/shared/fireworks.jpg" alt="" />
		</div>
	</body>
</html>

Inapplicable Example 5

Open in a new tab

The text inheriting its programmatic language from this div element is only whitespace.

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

Glossary

Accessible Name

The accessible name is the programmatically determined name of a user interface element that is included in the accessibility tree.

The accessible name is calculated using the accessible name and description computation.

For native markup languages, such as HTML and SVG, additional information on how to calculate the accessible name can be found in HTML Accessibility API Mappings 1.0, Accessible Name and Description Computation (working draft) and SVG Accessibility API Mappings, Name and Description (working draft).

For more details, see examples of accessible name.

Note: As per the accessible name and description computation, each element always has an accessible name. When no accessible name is provided, the element will nonetheless be assigned an empty ("") one.

Note: As per the accessible name and description computation, accessible names are flat string trimmed of leading and trailing whitespace. Notably, it is not possible for a non-empty accessible name to be composed only of whitespace since these must be trimmed.

Accessibility Support for Accessible Name

  • Because the accessible name and description computation is not clear about which whitespace are considered, browsers behave differently when trimming and flattening the accessible name. For example, some browsers completely trim non-breaking spaces while some keep them in the accessible name.
  • There exists a popular browser which does not perform the same trimming and flattening depending whether the accessible name comes from content, an aria-label attribute, or an alt attribute.
  • There exists a popular browser which assign no accessible name (null) when none is provided, instead of assigned an empty accessible name ("").
  • The accessible name and description computation suggest that if an aria-labelledby attribute refers to an existing but empty element, the computation should stop and return an empty name without defaulting to the next steps. Several user agents and assistive technologies chose to use the next step in the computation in this case.

Attribute value

The attribute value of a content attribute set on an HTML element is the value that the attribute gets after being parsed and computed according to specifications. It may differ from the value that is actually written in the HTML code due to trimming whitespace or non-digits characters, default values, or case-insensitivity.

Some notable case of attribute value, among others:

  • For enumerated attributes, the attribute value is either the state of the attribute, or the keyword that maps to it; even for the default states. Thus <input type="image" /> has an attribute value of either Image Button (the state) or image (the keyword mapping to it), both formulations having the same meaning; similarly, "an input element with a type attribute value of Text" can be either <input type="text" />, <input /> (missing value default), or <input type="invalid" /> (invalid value default).
  • For boolean attributes, the attribute value is true when the attribute is present and false otherwise. Thus <button disabled>, <button disabled="disabled"> and <button disabled=""> all have a disabled attribute value of true.
  • For attributes whose value is used in a case-insensitive context, the attribute value is the lowercase version of the value written in the HTML code.
  • For attributes that accept numbers, the attribute value is the result of parsing the value written in the HTML code according to the rules for parsing this kind of number.
  • For attributes that accept sets of tokens, whether space separated or comma separated, the attribute value is the set of tokens obtained after parsing the set and, depending on the case, converting its items to lowercase (if the set is used in a case-insensitive context).
  • For aria-* attributes, the attribute value is computed as indicated in the WAI-ARIA specification and the HTML Accessibility API Mappings.

This list is not exhaustive, and only serves as an illustration for some of the most common cases.

The attribute value of an IDL attribute is the value returned on getting it. Note that when an IDL attribute reflects a content attribute, they have the same attribute value.

Focusable

An element is focusable if one or both of the following are true:

Exception: Elements that lose focus during a period of up to 1 second after gaining focus, without the user interacting with the page the element is on, are not considered focusable.

Notes:

  • The 1 second time span is an arbitrary limit which is not included in WCAG. Given that scripts can manage the focus state of elements, testing the focusability of an element consistently would be impractical without a time limit.
  • The tabindex value of an element is the value of the tabindex attribute parsed using the rules for parsing integers. For the tabindex value to be different from null, it needs to be parsed without errors.

Included in the accessibility tree

Elements included in the accessibility tree of platform specific accessibility APIs are exposed to assistive technologies. This allows users of assistive technology to access the elements in a way that meets the requirements of the individual user.

The general rules for when elements are included in the accessibility tree are defined in the core accessibility API mappings. For native markup languages, such as HTML and SVG, additional rules for when elements are included in the accessibility tree can be found in the HTML accessibility API mappings (working draft) and the SVG accessibility API mappings (working draft).

For more details, see examples of included in the accessibility tree.

Programmatically hidden elements are removed from the accessibility tree. However, some browsers will leave focusable elements with an aria-hidden attribute set to true in the accessibility tree. Because they are hidden, these elements are considered not included in the accessibility tree. This may cause confusion for users of assistive technologies because they may still be able to interact with these focusable elements using sequential keyboard navigation, even though the element should not be included in the accessibility tree.

Known Primary Language Tag

A language tag has a known primary language tag 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 RFC 5646 language tag syntax, i.e. a sequence of subtags separated by hyphens, where a subtag is any sequence of alphanumerical characters. Language tag that are not valid according to the stricter RFC 5646 syntax (and ABNF grammar) definition can still have a known primary language tag. User agents and assistive technologies are more lenient in what they accept. This definition is consistent with the behavior of the :lang() pseudo-selector as defined by Selectors Level 3.

As an example, de-hello would be an accepted way to indicate German in current user agents and assistive technologies, despite not being valid according to RFC 5646 grammar. It has a known primary language tag (namely, de).

As a consequence of this definition, however, grandfathered tags do not have a known primary language tag.

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

Namespaced Element

An element with a specific namespaceURI value from HTML namespaces. For example an "SVG element" is any element with the "SVG namespace", which is http://www.w3.org/2000/svg.

Namespaced elements are not limited to elements described in a specification. They also include custom elements. Elements such as a and title have a different namespace depending on where they are used. For example a title in an HTML page usually has the HTML namespace. When used in an svg element, a title element has the SVG namespace instead.

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.

Programmatically Hidden

An HTML element is programmatically hidden if either it has a computed CSS property visibility whose value is not visible; or at least one of the following is true for any of its inclusive ancestors in the flat tree:

  • has a computed CSS property display of none; or
  • has an aria-hidden attribute set to true

Note: Contrary to the other conditions, the visibility CSS property may be reverted by descendants.

Note: The HTML standard suggests setting the CSS display property to none for elements with the hidden attribute. While not required by HTML, all modern browsers follow this suggestion. Because of this the hidden attribute is not used in this definition. In browsers that use this suggestion, overriding the CSS display property can reveal elements with the hidden attribute.

Text Inheriting its Programmatic Language from an Element

The text inheriting its programmatic language from an element E is composed of all the following texts:

An element F is an element inheriting its programmatic language from an element E if at least one of the following conditions is true (recursively):

  • F is E itself (an element always inherits its programmatic language from itself); or
  • F does not have a non-empty lang attribute, and is the child in the flat tree of an element inheriting its programmatic language from E; or
  • F is a fully active document element, has no non-empty lang attribute, and its browsing context container is an element inheriting its programmatic language from E.

Visible

Content perceivable through sight.

Content is considered visible if making it fully transparent would result in a difference in the pixels rendered for any part of the document that is currently within the viewport or can be brought into the viewport via scrolling.

Content is defined in WCAG.

For more details, see examples of visible.

Whitespace

Whitespace are characters that have the Unicode "White_Space" property in the Unicode properties list.

This includes:

  • all characters in the Unicode Separator categories, and
  • the following characters in the Other, Control category:

    • Character tabulation (U+0009)
    • Line Feed (LF) (U+000A)
    • Line Tabulation (U+000B)
    • Form Feed (FF) (U+000C)
    • Carriage Return (CR) (U+000D)
    • Next Line (NEL) (U+0085)

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.

ToolConsistencyCompleteReport
AlfaconsistentYesView Report
QualWebconsistentYesView Report
SortSiteconsistentYesView Report

Acknowledgments

Funding

  • WAI-Tools
Table of Contents