4.1 Identifying changes in language

Task:

Use the lang or xml:lang attribute to identify the natural language used in a document.

If you use a number of different languages on a page, make sure that any changes in language are clearly identified by using the lang or xml:lang attribute according to the HTML or XHTML version you use.

Note that HTML only offers the use of the lang attribute, while XHTML (transitionally) allows both attributes or only xml:lang, respectively, since lang was removed in XHTML 1.1.

Identifying changes in language are important for a number of reasons:

Example:

This example uses the lang attribute of the span element to define one phrase as French and another as Italian.

<p>
   And with a certain <span lang="fr">je ne sais
   quoi</span>, she entered both the room, and his life,
   forever. &quot;My name is Natasha,&quot; she said.
   &quot;<span lang="it">Piacere,</span>&quot; he
   replied in impeccable Italian, locking the door.
</p>
Example:

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.

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

HTML 4.01 "lang" attribute

Language tagging in HTML and XML