Techniques for WCAG 2.0

Skip to Content (Press Enter)

-

H58: Using language attributes to identify changes in the human language

Applicability

HTML and XHTML

This technique relates to:

User Agent and Assistive Technology Support Notes

See User Agent Support Notes for H58.

Description

The objective of this technique is to clearly identify any changes in language on a page by using the lang or xml:lang attribute, as appropriate for the HTML or XHTML version you use.

HTML 4.01 uses the lang attribute on elements. XHTML served as text/html uses the lang attribute and the xml:lang attribute on elements, in order to meet the requirements of XHTML and provide backward compatibility with HTML. XHTML served as application/xhtml+xml uses the xml:lang attribute on elements.

Note: HTML only offers the use of the lang attribute, while XHTML 1.0 (as a transitional measure) allows both attributes, and XHTML 1.1 allows only xml:lang.

Allowed values for the lang and xml:lang attributes are indicated in the resources referenced below. Language tags use a primary code to indicate the language, and optional subcodes (separated by hyphen characters) to indicate variants of the language. For instance, English is indicated with the primary code "en"; British English and American English can be distinguished by using "en-GB" and "en-US", respectively. Use of the primary code is important for this technique. Use of subcodes is optional but may be helpful in certain circumstances.

Examples

Example 1

This example demonstrates the use of the xml:lang attribute defining a quote written in German. This snippet could be included by an XHTML 1.1 document where lang is not allowed.

Example Code:

<blockquote xml:lang="de">
  <p>
    Da dachte der Herr daran, ihn aus dem Futter zu schaffen,
    aber der Esel merkte, daß kein guter Wind wehte, lief fort
    und machte sich auf den Weg nach Bremen: dort, meinte er,
    könnte er ja Stadtmusikant werden.
  </p>
</blockquote>   
            

Resources

Resources are for information purposes only, no endorsement implied.

Tests

Procedure

For each element in the document:

  1. Check that the human language of the content of the element is the same as the inherited language for the element as specified in HTML 4.01, Inheritance of language codes

For each lang attribute in the document:

  1. Check that the value of the lang attribute conforms to BCP 47: Tags for the Identification of Languages or its successor

For each xml:lang attribute in the document:

  1. Check that the value of the xml:lang attribute conforms to BCP 47: Tags for the Identification of Languages or its successor

Expected Results

If this is a sufficient technique for a success criterion, failing this test procedure does not necessarily mean that the success criterion has not been satisfied in some other way, only that this technique has not been successfully implemented and can not be used to claim conformance.

Techniques are Informative

Techniques are informative—that means they are not required. The basis for determining conformance to WCAG 2.0 is the success criteria from the WCAG 2.0 standard—not the techniques. For important information about techniques, please see the Understanding Techniques for WCAG Success Criteria section of Understanding WCAG 2.0.