xml:lang (HTML attribute)

Spec
Depr. Version
No XHTML 1.0
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+
Partial Partial Partial Partial

Syntax

xml:lang="language code"

Description

The xml:lang attribute is identical in its usage and purpose to the lang attribute, but with one difference: it must be applied within documents that use an XHTML doctype.

It may be that this attribute is used only once in a document—for example, in the root element html—but it may be used to indicate a change of language anywhere within a document:

<p>I told the guy in the best French I could muster:
    "<span lang="fr" xml:lang="fr">Mais j’ai oublié
    mes pantalons</span>" and hoped for the best.</p> 

Example

This example specifies the language of an XHTML Strict document as English:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

Value

This attribute takes approved International Standards Organisation (ISO) 2 letter language codes only (refer to the language codes reference for details).

Compatibility

Internet Explorer Firefox Safari Opera
5.5 6.0 7.0 1.0 1.5 2.0 1.3 2.0 3.0 9.2 9.5
Partial Partial Partial Partial Partial Partial Partial Partial Partial Partial Partial

As I mentioned in the description above, browsers don’t offer great support for the lang attribute, but its benefits extend beyond the browser itself (for instance, in terms of search and assistive technology). Language should be indicated for these reasons, as well as for the purposes of forwards compatibility.

User-contributed notes

There are no comments yet.

Related Products