Summarized test results:
HTML5, the lang attribute

Intended audience: users, XHTML/HTML coders (using editors or scripting), script developers (PHP, JSP, etc.), CSS coders, Web project managers, and anyone who wants to know how language declarations work in current browsers.

Updated

These tests check whether user agents recognize language declarations for HTML documents, and apply the expected prioritisation in case of mismatches between multiple declarations.

Note that the snapshot summaries of these test results are for released versions of the browsers tested. Versions that are still in development may provide better support for these features. The tests themselves do not test any vendor prefixes.

results

In order to tell whether the language information is available we use :lang. We run control tests that will raise a flag if :lang is not supported by the browser.

To see the test, click on the link in the left-most column. To see detailed results for a single test, click on the link in the right-most column. To submit test data for a single test, click on the link in the right-most column and then follow the link on that page.

The tables show the latest results from the W3C Test Framework. Below the tables are summaries of the results at a given date. The table data may be more up-to-date than the summary. The tables may also contain some incorrectly scored tests, and tests that relate to non-released versions of browsers. These are not included in the summary.

Basic declarations

Snapshot summary, 2013-07-03
Firefox 22.0, Opera 12.15, Internet Explorer 10 & 9, Chrome 27.0.1453.116, Safari 5.1.9

All browsers recognized language declarations in the html tag using the lang attribute.

If xml:lang is used instead of the lang attribute, the declaration is not recognized, which is to be expected.

Declarations in the HTTP header were recognized by IE, Firefox and Chrome, but not by Opera, or Safari.

Declarations in the meta pragma-set default were recognized by all browsers tested except Opera.

These results mean that declaring language for text-processing purposes is best done in the html tag. Declarations in the HTTP header or the meta pragma-set default are not interoperably supported across all browsers.

Assertion Gecko Presto Trident WebKit Detailed results
lang attribute in html tag The browser will recognize a language declared in a lang attribute on the html tag.
xml:lang attribute in html tag The browser will NOT recognize a language declared in an xml:lang attribute on the html tag.
HTTP header The browser will recognize a language declared in the HTTP header, when there is no internal language declaration.
pragma-set default The browser will recognize a language declared in a meta element in the head using http-equiv='Content-Language' content='..' (with a single language tag value), when there is no other language declaration inside the document.

Conflicting declarations

Snapshot summary, 2013-07-03
Firefox 22.0, Opera 12.15, Internet Explorer 10 & 9, Chrome 27.0.1453.116, Safari 5.1.9

From the basic tests above, Opera doesn't recognize language in the HTTP header, and neither Opera nor Safari recognise language set in the meta element. This is why Opera and Safari pass test 005 and Opera passes test 007. For test 006, the Opera result should be ignored.

For browsers that support declarations in HTTP (IE, Firefox, Chrome), in-page declarations always had precedence over the HTTP declaration.

For the browsers that support declarations in meta elements (IE, Firefox, Crome and Safari), a language attribute with a value always had precedence over the meta element.

Assertion Gecko Presto Trident WebKit Detailed results
HTTP header and html lang If there is a conflict between the language declarations in the HTTP header and the html element using lang, the browser will recognize the language declared in the html element.
HTTP header and meta element If there is a conflict between the language declarations in the HTTP header and the Content-Language meta element, the UA will recognize the language declared in the meta element.
html lang and meta elements If there is a conflict between the language declared using lang in the html element and that in the meta element, the UA will recognize the language declared in the html element.

Empty language value

Snapshot summary, 2013-07-03
Firefox 22.0, Opera 12.15, Internet Explorer 10 & 9, Chrome 27.0.1453.116, Safari 5.1.9

From the basic tests above, Opera doesn't recognize language in the HTTP header, and neither Opera nor Safari recognise language set in the meta element. This is why Opera and Safari pass test 010 and Opera passes test 009.

An empty lang attribute value overrode an earlier lang attribute in all browsers.

For browsers that support declarations in HTTP (IE, Firefox, Chrome), an empty value in a lang attribute killed any value from the HTTP declaration in IE and Chrome, but did not in Firefox.

For the browsers that support declarations in meta elements (IE, Firefox, Safari, Chrome), an empty lang value on the html element killed any default value from the meta element, except (again) for Firefox.

The Firefox is unexpected, because when the attribute on the html tag has a value it does take precedence over the HTTP header (see the earlier section).. The question is whether this is a bug due to a misinterpretation of the meaning of the empty language value.

Assertion Gecko Presto Trident WebKit Detailed results
lang="..." vs lang="" If an element contains a lang attribute with an empty value, the value of a lang attribute higher up the document tree will no longer be applied to the content of that element.
lang="" vs HTTP If the HTTP header contains a language declaration but the html element uses an empty lang value, the UA will not recognize the language declared in the HTTP header.
lang="" vs meta Content-Language If the meta Content-Language element contains a language declaration but the html element uses an empty lang value, the UA will not recognize the language declared in the meta Content-Language element.

Declarations containing multiple languages

Snapshot summary, 2013-07-03
Firefox 22.0, Opera 12.15, Internet Explorer 10 & 9, Chrome 27.0.1453.116, Safari 5.1.9

From the basic tests above, Opera doesn't recognize language in the HTTP header, and neither Opera nor Safari recognise language set in the meta element. Therefore test 012 should be ignored for Opera and Safari and test 011 should be ignored for Opera.

Of the browsers that recognize HTTP declarations (IE, Chrome, Firefox), only IE ignored the declaration. In Chrome and Firefox the language of the element tested had been set to all three languages of the list in the HTTP header. This doesn't really make sense.

Of the browsers that recognize declarations in meta elements (all except Opera), all except Firefox ignored the declarations where the meta element value contained multiple languages.

Assertion Gecko Presto Trident WebKit Detailed results
Multiple languages in HTTP header [Exploratory test] The browser will not recognize a language declaration in the HTTP Content Language header when more than one language is declared.
Multiple languages in Content-Language meta element The UA will not recognize a language declaration in the Content-Language meta element when more than one language is declared.