Techniques for WCAG 2.0

On this page:

-

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

## Applicability

HTML and XHTML

This technique relates to:

- Success Criterion 3.1.2 (Language of Parts)
  - How to Meet 3.1.2 (Language of Parts)
  - Understanding Success Criterion 3.1.2 (Language of Parts)

## User Agent and Assistive Technology Support Notes

Additional subtags for region, script, variant or other aspects may lead to errors in language switching in older versions of some screenreaders.

JAWS 8.0 can be configured to change language automatically on the basis of the lang attribute. However, it only switches amongst major languages as indicated by the primary code. If a regional language variant is indicated with a language subcode, JAWS will use the default variant for which it is configured.

## 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.

- HTML 4.01 lang attribute

- XML 1.0 xml:lang attribute

- Inheritance of language codes.

- BCP 47: Tags for the Identification of Languages .

- Language tags in HTML and XML

## Related Techniques

- H57: Using language attributes on the html element

## 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

- All checks above are true.

- Top
- Contents
- Intro
- Previous: Technique H57
- Next: Technique H59