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.

The tables show results for tests run on the date shown. Above the tables are summaries of the results at that date. The table data may be more up-to-date than the summary. If the tables contain some incorrectly scored tests, or tests that relate to non-released versions of browsers, these are not included in the summary.

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.

Basic declarations

Snapshot summary, 2014-02-17
Firefox 27.0, Chrome 32.0.1700.107, Safari 6.1.1, Internet Explorer 9, Opera 19.0

All browsers tested 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.

All the most recent versions of browsers recognised declarations in the HTTP header, however slightly older versions of Opera and Safari don't. The version of Safari tested that failed is the standard version for Snow Leopard. The version of Opera runs on the Presto engine.

Declarations in the meta pragma-set default were recognized by all recent versions of browsers tested, however not in the Presto-based older version of Opera.

These results would indicate that declaring language for text-processing purposes can be done in the html tag, the HTTP header or the meta element as long as the user has access to the latest versions of those browsers. However this is not the case for slightly older versions of some browsers, so it is still best done in the html tag.

Assertion Firefox Chrome Safari Opera IE 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, 2014-02-17
Firefox 27.0, Chrome 32.0.1700.107, Safari 6.1.1, Internet Explorer 9, Opera 19.0

If a browser version doesn't pass the test the-lang-attribute-003 above, you should ignore the results for tests -005 and -006.

If a browser version doesn't pass the test the-lang-attribute-004 above, you should ignore the results for tests -006 and -007.

This summary focuses on only the most recent versions of the browsers tested

In-page declarations always have precedence over the HTTP declaration.

A language attribute with a value always has precedence over the meta element.

Assertion Firefox Chrome Safari Opera IE 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, 2014-02-17
Firefox 27.0, Chrome 32.0.1700.107, Safari 6.1.1, Internet Explorer 9, Opera 19.0

If a browser version doesn't pass the test the-lang-attribute-003 above, you should ignore the results for test -009.

If a browser version doesn't pass the test the-lang-attribute-004 above, you should ignore the results for test -010.

This summary focuses on only the most recent versions of the browsers tested.

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

An empty value in a lang attribute killed any value from the HTTP declaration in IE, Chrome, Safari and Opera, but not in Firefox.

An empty lang value on the html element killed any default value from the meta element, except (again) for Firefox.

The Firefox behaviour 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 Firefox Chrome Safari Opera IE 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, 2014-02-17
Firefox 27.0, Chrome 32.0.1700.107, Safari 6.1.1, Internet Explorer 9, Opera 19.0

If a browser version doesn't pass the test the-lang-attribute-003 above, you should ignore the results for test -011.

If a browser version doesn't pass the test the-lang-attribute-004 above, you should ignore the results for test -012.

This summary focuses on only the most recent versions of the browsers tested.

Only IE, Safari and Opera ignored the HTTP declaration when it had multiple values. 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.

All the browsers except Firefox ignored the declarations where the meta element value contained multiple languages. Again, Firefox set the language of the text to three languages, which doesn't make sense for text-processing.

Assertion Firefox Chrome Safari Opera IE Detailed results
Multiple languages in HTTP header [Exploratory] 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.