Validity of HTML Lang attribute

  • Rule Typeatomic
  • Rule ID: bf051a
  • Last modified: Aug 21, 2019
  • Accessibility Requirements Mapping
    • 3.1.1 Language of Page (Level: A)
      • Learn More about 3.1.1 (Language of Page)
      • Required for conformance to WCAG 2.0 and above on level A 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 the lang or xml:lang attribute has a valid language subtag.

Applicability

The root element of the page, if it is an html element with a lang and/or xml:lang attribute that is not empty ("").

Expectation

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

Assumptions

There are currently no assumptions

Accessibility Support

There are known combinations of a popular operating system with browsers and assistive technologies that do not support the lang and xml:lang attributes.

While HTML5 specification indicates that xml:lang attribute takes priority over lang attribute, certain assistive technologies prioritise lang over xml:lang instead.

Background

Test Cases

Passed

Passed Example 1

The lang attribute specified has a non-empty value & a valid primary language subtag.

<html lang="fr"></html>

Passed Example 2

The xml:lang attribute specified has a non-empty value & a valid primary language subtag.

<html xml:lang="fr"></html>

Passed Example 3

The lang and xml:lang attribute specified has a non-empty value & a valid primary language subtag.

<html xml:lang="fr" lang="fr"></html>

Passed Example 4

The lang attribute specified has a non-empty value & a valid primary language subtag. The rule checks for the presence of either lang or xml:lang. Empty value specified for the other attribute is ignored.

<html lang="fr" xml:lang=""></html>

Passed Example 5

The xml:lang attribute specified has a non-empty value & a valid primary language subtag. The rule checks for the presence of either lang or xml:lang. Empty value specified for the other attribute is ignored.

<html lang="" xml:lang="nl"></html>

Failed

Failed Example 1

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

<html lang="xyz"></html>

Failed Example 2

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

<html xml:lang="xyz"></html>

Failed Example 3

Both the lang and xml:lang value specified are not valid values for primary language subtag.

<html xml:lang="xyz" lang="xyz"></html>

Failed Example 4

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

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

Failed Example 5

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

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

Failed Example 6

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

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

Failed Example 7

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

<html lang=" "></html>

Inapplicable

Inapplicable Example 1

The rule applies to html element and hence usage of lang attribute in svg element is not applicable.

<svg xmlns="http://www.w3.org/2000/svg" lang="fr"></svg>

Inapplicable Example 2

The rule applies to html element and hence usage of xml:lang attribute in svg element is not applicable.

<svg xmlns="http://www.w3.org/2000/svg" xml:lang="fr"></svg>

Inapplicable Example 3

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

<html lang=""></html>

Inapplicable Example 4

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

<html xml:lang=""></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, 2019fix: update links to WCAG21 resources (#776)
Jul 26, 2019Editorial changes (#702)
Jul 17, 2019fix: test if definition for all referenced glossary terms exist (#634)
Jul 9, 2019Bugfix closing svg tag (#657)
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 8, 2019chore: fix invalid frontmatter in updated templates (#544)
May 7, 2019Template update - Validity of HTML Lang attribute (#510)
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)
Oct 15, 2018Add examples of syntactically invalid language attributes (#294)
Oct 10, 2018chore: Mark all SVG documents and add missing namespaces (#300)
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)
Jun 26, 2018FINAL: SC3-1-1-html-lang-valid (#109)
Jun 25, 2018FINAL: SC3-1-1-html-has-lang (#107)

Useful Links


Implementations

Tool NameCreated ByReport
AlfaSiteimproveView Report
QualWebLASIGE, Faculdade de Ciências da Universidade de LisboaView Report

Acknowledgements