Techniques for WCAG 2.0

Skip to Content (Press Enter)

-

H57: Using language attributes on the html element

Applicability

HTML 4, XHTML 1.0 and XHTML 1.1

This technique relates to:

Description

The objective of this technique is to identify the default language of a document by providing the lang and/or xml:lang attribute on the html element.

Identifying the language of the document is important for a number of reasons:

HTML 4.01 uses the lang attribute of the html element. XHTML served as text/html uses the lang attribute and the xml:lang attribute of the html element, in order to meet the requirements of XHTML and provide backward compatibility with HTML. XHTML served as application/xhtml+xml uses the xml:lang attribute of the html element. Both the lang and the xml:lang attributes can take only one value.

Note: HTML only offers the use of the lang attribute, while XHTML 1.0 (as a transitional measure) allows both attributes, and XHTML 1.1 allows only xml:lang.

Examples

Example 1

This example defines the content of an HTML 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"> 
<head>
  <title>document écrit en français</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>  
<body>     
	...document écrit en français...   
</body>
</html>

Example 2

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 in order to meet the requirements of XHTML and provide backward compatibility with HTML.

<!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>
  <title>document écrit en français</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body> 
...document écrit en français...      
</body>
</html>
						

Example 3

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>
  <title>document écrit en français</title>
	<meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
</head>
<body> 
	...document écrit en français... 
</body>
</html>

Resources

Resources are for information purposes only, no endorsement implied.

Tests

Procedure

  1. Examine the html element of the document.

  2. Check that the html element has a lang and/or xml:lang attribute.

  3. Check that the value of the lang attribute conforms to BCP 47: Tags for the Identification of Languages or its successor .

Expected Results