Summary
Setting the language ensures that assistive technologies correctly interpret and render the text.
Techniques
-
Set the
lang
andxml:lang
attributes on the roothtml
element. [[WCAG-3.1.1]] -
Set the
lang
andxml:lang
attributes whenever the default language changes. [[WCAG-3.1.2]] -
Ensure language codes conform to BCP 47. [[WCAG-3.1.1]]
Examples
Frequently Asked Questions
- Is it necessary to specify a default language in content files?
The default language(s) for the publication are formally defined in the package document, but that information is not used when rendering the content. To ensure the proper language for braille rendering or TTS playback, the language must be set in each document.
- Is it necessary to specify both the
lang
andxml:lang
attributes? For optimal accessibility both should be specified when creating XHTML content. Assistive technologies may only recognize one or the other attribute.
In addition, if XHTML documents are rendered as HTML by a user agent, only the
lang
attribute may be recognized.The
xml:lang
attribute is not valid in HTML documents, only in XHTML.
Explanation
Specifying a document's default language — as well as any changes within the document, such as instances of foreign language terms or dialogue or passages in another language — helps ensure that assistive technologies can correctly render the text (e.g., that the correct braille characters are presented, or a voice capable of rendering the language gets used).
To define the default language of a document, the lang
and xml:lang
language attributes need to be attached to the root html
element. The language code defined
in these attributes should match one of the language codes specified in a dc:language
element in the package document's metadata section (see the faq for more
information).
When attached to elements within the body, the language attributes identify the language of the text content of that element (i.e., to identify a change in language).