HTML and XHTML
This technique relates to:
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:
It allows braille translation software to substitute control codes for accented characters, and insert control codes necessary to prevent erroneous creation of Grade 2 braille contractions.
Speech synthesizers that support multiple languages will be able to orient and adapt to the pronunciation and syntax that are specific to the language of the page, speaking the text in the appropriate accent with proper pronunciation.
Marking the language can benefit future developments in technology, for example users who are unable to translate between languages themselves will be able to use machines to translate unfamiliar languages.
Marking the language can also assist user agents in providing definitions using a dictionary.
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 1:
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
.
Note 2: Allowed values for the lang and xml:lang attributes are indicated in the resources referenced below. Language tags use a primary code to indicate the language, and optional subcodes (separated by hyphen characters) to indicate variants of the language. For instance, English is indicated with the primary code "en"; British English and American English can be distinguished by using "en-GB" and "en-US", respectively. Use of the primary code is important for this technique. Use of subcodes is optional but may be helpful in certain circumstances.
This example defines the content of an HTML document to be in the French language.
Example Code:
<!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>
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.
Example Code:
<!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>
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.
Example Code:
<!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 are for information purposes only, no endorsement implied.
Examine the html
element of the document.
Check that the html
element has a lang
and/or
xml:lang
attribute.
Check that the value of the lang
attribute conforms to BCP 47: Tags for the
Identification of Languages or its successor and reflects the primary language used by the Web page.
The above checks are all true.
If this is a sufficient technique for a success criterion, failing this test procedure does not necessarily mean that the success criterion has not been satisfied in some other way, only that this technique has not been successfully implemented and can not be used to claim conformance.
Techniques are informative—that means they are not required. The basis for determining conformance to WCAG 2.0 is the success criteria from the WCAG 2.0 standard—not the techniques. For important information about techniques, please see the Understanding Techniques for WCAG Success Criteria section of Understanding WCAG 2.0.