# Using language attributes to identify changes in the human language

ID: H58

3.1.2 Language of Parts

Technology: html

Type: Technique

## When to Use

HTML

## Description

The objective of this technique is to clearly identify any changes in language on a page by using the `lang` attribute.

Allowed values for the `lang` attribute are indicated in the resources referenced below. Language tags use a primary code to indicate the language, and optional sub-codes (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 sub-codes is optional but may be helpful in certain circumstances.

## Examples

### The use of the `lang` attribute to define a quote written in German

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

## 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 - The `lang` and `xml:lang` attributes.

For each `lang` attribute in the document:

1. Check that the value of the `lang` attribute conforms to BCP 47: Tags for Identifying Languages; Matching of Language Tags or its successor.
2. Check that the language code matches the language of the content it applies to.

### Expected Results

- All checks above are true.

## Related Techniques

- H57

## Resources

- HTML - The `lang` and `xml:lang` attributes.
- HTML "`lang`" attribute on the Mozilla Developer Network.
- BCP 47: Tags for Identifying Languages; Matching of Language Tags.
- Language tags in HTML and XML.