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.
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.
In order to tell whether the language information is available, we test a feature, :lang
, that makes use of language information in a detectable way. Unfortunately, such features are not uniformly supported across current user agents, and so conclusions must be drawn with care. We run control tests that will raise a flag if :lang
is not supported by the user agent – if the control test is not supported, the related tests are not relevant. If a test proves positive, that should show that the language declaration was recognized.
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.
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. | language-declarations-001 | ||||
xml:lang attribute in html tag | [Exploratory test] The browser will not recognize a language declared in a xml:lang attribute on the html tag. | language-declarations-002a | ||||
HTTP header | The browser will recognize a language declared in the HTTP header, when there is no internal language declaration. | language-declarations-003 | ||||
Content-Language meta element | 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. | language-declarations-004 |
Links: Section 3.2.3.3 • Latest results for section 3.2.3.3 • Submit data for section 3.2.3.3 • Related tests
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 and Firefox, but not by Opera, Safari or Chrome.
Declarations in the Content-Language meta
element 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. HTTP declarations fail for Opera, Safari and Chrome. Declarations in the meta
tag do better, but don't work in Opera (or IE7). On the other hand, declarations in the html
tag work for all browsers.
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 UA will recognize the language declared in the html element. | language-declarations-009 | ||||
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. | language-declarations-011 | ||||
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. | language-declarations-012 |
Links: Section 3.2.3.3 • Latest results for section 3.2.3.3 • Submit data for section 3.2.3.3 • Related tests
Meaningful results could only be obtained for where both the types of declaration being tested were supported by a given browser. This reduced the number of valid tests significantly, and ruled out any results at all for Opera.
For browsers that support declarations in HTTP (IE and Firefox), in-page declarations always had precedence over the HTTP declaration.
For the browsers that support declarations in meta elements (IE, Firefox, Safari and Chrome), a language attribute with a value always had precedence over the meta
element.
Assertion | Gecko | Presto | Trident | WebKit | Detailed results | |
---|---|---|---|---|---|---|
lang="..." vs lang="" | If an element contains a language attribute with an empty value, the value of a language attribute higher up the document tree will no longer be applied to the content of that element. | language-declarations-018 | ||||
lang="" vs HTTP | If the HTTP header contains a language declaration but the html element uses an empty lang attribute, the UA will not recognize the language declared in the HTTP header. | language-declarations-014 | ||||
lang="" vs meta Content-Language | If the meta Content-Language element contains a language declaration but the html element uses an empty lang attribute, the UA will not recognize the language declared in the meta Content-Language element. | language-declarations-015 |
Links: Section 3.2.3.3 • Latest results for section 3.2.3.3 • Submit data for section 3.2.3.3 • Related tests
Meaningful results could only be obtained for where both the types of declaration being tested were supported by a given browser. This reduced the number of valid tests significantly.
An empty lang attribute value overrode an earlier lang
attribute in all browsers.
For browsers that support declarations in HTTP (IE and Firefox), an empty value in a lang
attribute killed any value from the HTTP declaration in IE, but did not in Firefox.
For the browsers that support declarations in both html
and meta
elements (IE, Firefox, Safari and Chrome), an empty lang
value on the html
element killed any default value from the meta element, except (again) for Firefox.
On the other hand, there seems to be some slightly unexpected behaviour in Firefox, where an empty language value in an attribute has a lower precedence than an HTTP or Content-Language meta declaration (whereas that is not the case for language attribute values that are not empty). 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 | |
---|---|---|---|---|---|---|
First of multiple languages in HTTP header (html5) | The UA will not recognize a language declaration in the HTTP Content Language header where more than one language is declared. | language-declarations-005 | ||||
First of multiple languages in Content-Language meta element | The UA will not recognize a language declaration in the Content-Language meta element where more than one language is declared. | language-declarations-007 |
Links: Section 3.2.3.3 • Latest results for section 3.2.3.3 • Submit data for section 3.2.3.3 • Related tests
HTML5 explicitly requires that if an HTTP header or meta
element contains more than one language value, it should not be used to set the language of the content.
Of the browsers that recognize HTTP declarations (IE and Firefox), only IE ignored the declaration.
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.