4.1 Identifying the primary language

This technique relates to the following sections of the guidelines:

Task:

Use the lang attribute of the html element to define the document's language.

It is important to identify the primary language of a document using markup (as shown in the examples).  The lang attribute allows assistive technology to orient and adapt to the pronunciation and syntax that are specific to the language of the page. This attribute may also play a major role in the emerging global, multi-lingual, simultaneous translation web environment.

There are other methods of specifying the primary language.  information on the use and support of HTTP headers and the meta element are provided by the W3C Internationalization Group.  The lang attribute of the html element is the preferred technique since it takes precedence over these other methods.

Example:

The use of the lang attribute varies with the document and content type.

This example defines the content of an HTML 4.01 document to be in the French language.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML lang="fr">
<BODY>
...document écrit en français...
</BODY>
</HTML>

This example defines the content of an XHTML 1.0 document with content type of text/html to be in the
French language. Both the lang and xml:lang attributes are specified.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr" >
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head> 
<body>
...document écrit en français...
</body>
</html>

This example defines the content of an XHTML 1.1 document with content type of application/xhtml+xml to be in the French language. Only the xml:lang attribute is specified.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
</head>
<body>
...document écrit en français...
</body>
</html>

Resources: