Valid body lang attribute

  • Rule Typeatomic
  • Rule ID: de46e4
  • Last modified: Aug 21, 2019
  • 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: not satisfied
        • All passed outcomes: further testing is needed
        • An inapplicable outcome: further testing is needed
  • Input Aspects

Description

This rule checks that lang or xml:lang attributes on elements within the body of a web page have a valid language subtag.

Applicability

This rules applies to each HTML or SVG element that is a descendant in the flat tree (work in progress) of the body element and has a lang or xml:lang attribute that is not empty ("").

Expectation

The lang and xml:lang attributes of the test target have a valid language subtag if the attribute is not empty ("").

Assumptions

This rule assumes that the presence of a lang or xml:lang attribute is being used to comply to WCAG. This rule doesn't test if the attribute is needed to comply to WCAG.

Accessibility Support

There are no major accessibility support issues known for this rule.

Background

Test Cases

Passed

Passed Example 1

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

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

Passed Example 2

The xml:lang attribute has a value that is not empty ("") and has a valid primary language subtag.

<html>
	<body>
		<p xml:lang="DE"></p>
	</body>
</html>

Passed Example 3

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

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

Passed Example 4

The lang and xml:lang attribute values are not empty ("") and both have a valid primary language subtag.

<html>
	<body>
		<p lang="en" xml:lang="en-GB">Good Morning.</p>
	</body>
</html>

Passed Example 5

The lang and xml:lang attribute values are either empty ("") or have a valid primary language subtag.

<html>
	<body>
		<p lang="en" xml:lang="">Good Morning.</p>
	</body>
</html>

Failed

Failed Example 1

The lang attribute value is not a valid primary language subtag.

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

Failed Example 2

The xml:lang attribute value is not a valid primary language subtag.

<html>
	<body>
		<p xml:lang="english"></p>
	</body>
</html>

Failed Example 3

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

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

Failed Example 4

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

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

Failed Example 5

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

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

Failed Example 6

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

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

Inapplicable

Inapplicable Example 1

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

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

Inapplicable Example 2

An empty value for lang attribute is ignored by this rule, as the applicability specifies only values that are not empty ("").

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

Inapplicable Example 3

An empty value for xml:lang attribute is ignored by this rule, as the applicability specifies only values that are not empty ("").

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

Glossary

Outcome

key: outcome

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: Implementers 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.


Changelog

Aug 21, 2019test: add tests to verify h4 headings (#810)
Aug 21, 2019fix: update links to WCAG21 resources (#776)
Aug 21, 2019Editorial changes (#725)
May 18, 2019chore: Validating rules frontmatter on CI (#551)
May 15, 2019Glossary and Rule update: Replacing "non-empty" definition (#430)
May 9, 2019Chore: Adapt site to ACT Rules CR format (#547)
May 7, 2019Template update - Valid body lang attribute (#520)
May 7, 2019Fix some incorrect test cases (#477)
Apr 29, 2019chore: rename files and update associations (#489)
Apr 16, 2019chore: add unique id to all rules (#478)
Apr 15, 2019chore: WCAG ACT RULES CG Website Update (#437)
Mar 21, 2019Added assumption for SC3-1-2-lang-valid (#413)
Nov 12, 2018chore: remove selector `data-rule-target` (#347)
Oct 15, 2018Add examples of syntactically invalid language attributes (#294)
Oct 9, 2018Fix: testcase generation (#296)
Aug 30, 2018Chore: Update test cases format and descriptions (#230)
Jul 13, 2018fix: links in background were not anchors (#187)
Jul 10, 2018FINAL: Fix BCP47 reference to language subtag in expectation (#173)
Jul 1, 2018FINAL: SC3-1-2-lang-valid (#132)

Useful Links


Implementations

Tool NameCreated ByReport
AlfaSiteimproveView Report

Acknowledgements