Setting the language ensures that assistive technologies correctly interpret and render the text.



Example 1 — Declaring page language

The lang and xml:lang attributes are set on the html element to declare the language for the page.

<html … lang="en" xml:lang="en">
Example 2 — Overriding the page language

The lang and xml:lang attributes are used on span elements within the body to change the language from English to French.

<html … lang="en" xml:lang="en">
       Harsh gargoyle face that warred against me 
       over our mess of hash of lights in 
       <span xml:lang="fr" lang="fr">rue 
       Saint-André-des-Arts</span>. In words of
       words for words, palabras. Oisin with
       Patrick. Faunman he met in Clamart woods,
       brandishing a winebottle.
       <i xml:lang="fr" lang="fr">C'est 
       vendredi saint!</i> Murthering Irish.
       His image, wandering, he met. I mine. I 
       met a fool i'the forest.

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 and xml: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.


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

Related Links