Setting the language ensures that assistive technologies correctly interpret and render the text.
xml:langattributes on the root
xml:langattributes whenever the default language changes. [[WCAG-3.1.2]]
Ensure language codes conform to BCP 47. [[WCAG-3.1.1]]
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
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
langattribute may be recognized.
xml:langattribute is not valid in HTML documents, only in XHTML.
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
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
element in the package document's metadata section (see the faq for more
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).