Summarized test results:
Language selectors

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 selectors work in current browsers.

Updated

These tests check whether various methods of selecting language in CSS selectors work for styling text in HTML and XHTML.

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

Note that some tests are served as text/html, and others as application/xhtml+xml, since there are two different attributes used for declaring language. The lang attribute is part of the HTML vocabulary, and the xml:lang attribute is an XML attribute.

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.

:lang with lang

Assertion Gecko Presto Trident WebKit Detailed results
:lang(es), lang="es" A :lang value that matches an identical lang attribute value will produce styling.
:lang(es), lang="es" (xml) [Exploratory test] A :lang value that matches an identical lang attribute value will produce styling in a page served as XML.
:lang(es), lang="ES" A :lang value will match a lang attribute value regardless of case differences.
:lang(es), lang="ES" (xml) [Exploratory test] A :lang value will match a lang attribute value regardless of case differences in a page served as XML.
:lang(es), lang="es-MX" A :lang value will match a lang attribute value when the latter contains additional subtags.
:lang(es-MX), lang="es" A :lang value will not match a lang attribute value when the former contains more subtags.
lang(es), lang="mx-es" When the :lang value uses a single subtag, it will not match against an attribute value where it appears in a different position.
:lang(en-GB), lang="en-GB" A :lang value with language and region subtags will match a lang attribute value with the same subtags.
:lang(en-GB), lang="en-GB-scouse" A :lang value with a multiple subtags will match a lang attribute value with multiple subtags as long as the first part is the same.
:lang(en-GB), lang="en-US" A :lang value and a lang attribute value will not match if their region subtags differ.
:lang(az-Arab-IR), lang="az-Arab-IR" A :lang value with language, script and region subtags will match a lang attribute value with the same language, script and region subtags.
:lang(az-Arab-IR), lang="az-IR" A :lang value with language, script and region subtags will not match a lang attribute value with the script subtag missing.
:lang(cs-CZ), lang="cs-Latn-CZ" A :lang value with language and region subtags will not match a lang attribute value with language, script and region subtags.
:lang(az-Arab-IR), lang="az-arab-IR" A :lang value will match a lang attribute value regardless of case differences in the script tag.
:lang, Inheritance by inline elements When styling is defined for a block element using :lang and the lang attribute, the styling should still be picked up by inline elements contained by that block element.
:lang, Inheritance from an ancestor, block elements When styling is defined for a block element using :lang but the language is only declared using a lang attribute on an ancestor element, the styling should still be picked up.
:lang, Inheritance from an ancestor, inline elements When styling is defined for an inline element using :lang but the language is only declared using a lang attribute on an ancestor element, the styling should still be picked up.

Snapshot summary, 2011-12-17

All browsers support :lang as expected.

In no browser did CSS selectors match a language set using the xml:lang (rather than lang) attribute.

Perhaps surprisingly, all browsers tested also supported :lang with a lang attribute when the document was served as XML.

:lang with xml:lang

Assertion Gecko Presto Trident WebKit Detailed results
:lang(es), xml:lang="es" A :lang value that matches an identical xml:lang attribute value will produce styling in pages served as XML.
:lang(es), xml:lang="es" (html) [Exploratory test] A :lang value that matches an identical xml:lang attribute value will not produce styling in pages served as HTML.
:lang(es), xml:lang="ES" A :lang value will match an xml:lang attribute value regardless of case differences.
:lang(es), xml:lang="es-MX" A :lang value will match an xml:lang attribute value when the latter contains additional subtags.
:lang(es-MX), xml:lang="es" A :lang value will not match an xml:lang attribute value when the former contains more subtags.
lang(es), xml:lang="mx-es" When the :lang value uses a single subtag, it will not match against an xml:lang attribute value where that value appears in a different position.
:lang(en-GB), xml:lang="en-GB" A :lang value with language and region subtags will match a xml:lang attribute value with the same subtags.
:lang(en-GB), xml:lang="en-GB-scouse" A :lang value with a multiple subtags will match a xml:lang attribute value with multiple subtags as long as the first part is the same.
:lang(en-GB), xml:lang="en-US" A :lang value and a xml:lang attribute value will not match if their region subtags differ.
:lang(az-Arab-IR), xml:lang="az-Arab-IR" A :lang value with language, script and region subtags will match a xml:lang attribute value with the same language, script and region subtags.
:lang(az-Arab-IR), xml:lang="az-IR" A :lang value with language, script and region subtags will not match a xml:lang attribute value with the script subtag missing.
:lang(cs-CZ), xml:lang="cs-Latn-CZ" A :lang value with language and region subtags will not match a xml:lang attribute value with language, script and region subtags.
:lang(az-Arab-IR), xml:lang="az-arab-IR" A :lang value will match an xml:lang attribute value regardless of case differences in the script tag.
:lang, Inheritance by inline elements When styling is defined for a block element using :lang and the xml:lang attribute, the styling should still be picked up by inline elements contained by that block element.
:lang, Inheritance from an ancestor, block elements When styling is defined for a block element using :lang but the language is only declared using an xml:lang attribute on an ancestor element, the styling should still be picked up.
:lang, Inheritance from an ancestor, inline elements When styling is defined for an inline element using :lang but the language is only declared using an xml:lang attribute on an ancestor element, the styling should still be picked up.

Snapshot summary, 2011-12-17

All browsers support :lang as expected with xml:lang in documents served as XML.

lang and xml:lang precedence

Assertion Gecko Presto Trident WebKit Detailed results
:lang, xml:lang vs. lang When an xml:lang attribute and a lang attribute on the same element have different values, the xml:lang value will match :lang for pages served as application/xhtml+xml.

Snapshot summary, 2011-12-17

For documents served as XML, if both lang attribute and xml:lang attribute are present and have differing values, the xml:lang attribute always takes precedence.

lang |= with lang

Assertion Gecko Presto Trident WebKit Detailed results
[lang|="es"], lang="es" A lang|= value that matches an identical lang attribute value will produce styling.
[lang|="es"], lang="es" (xml) [Exploratory test] A lang|= value that matches an identical lang attribute value will produce styling in a page served as XML.
[lang|="es"], lang="ES" A lang|= value will match a lang attribute value regardless of case differences.
[lang|="es"], lang="ES" (xml) [Exploratory test] A lang|= value will match a lang attribute value regardless of case differences in a page served as XML.
[lang|="es"], lang="es-MX" A lang|= value will match a lang attribute value when the latter contains additional subtags.
[lang|="es-MX"], lang="es" A lang|= value will not match a lang attribute value when the former contains more subtags.
[lang|="es"], lang="mx-es" When the lang|= value uses a single subtag, it will not match against an attribute value where it appears in a different position.
[lang|="en-GB"], lang="en-GB" A lang|= value with language and region subtags will match a lang attribute value with the same subtags.
[lang|="en-GB"], lang="en-GB-scouse" A lang|= value with a multiple subtags will match a lang attribute value with multiple subtags as long as the first part is the same.
[lang|="en-GB"], lang="en-US" A lang|= value and a lang attribute value will not match if their region subtags differ.
[lang|="az-Arab-IR"], lang="az-Arab-IR" A lang|= value with language, script and region subtags will match a lang attribute value with the same language, script and region subtags.
[lang|="az-Arab-IR"], lang="az-IR" A lang|= value with language, script and region subtags will not match a lang attribute value with the script subtag missing.
[lang|="cs-CZ"], lang="cs-Latn-CZ" A lang|= value with language and region subtags will not match a lang attribute value with language, script and region subtags.
[lang|="az-Arab-IR"], lang="az-arab-IR" A lang|= value will match a lang attribute value regardless of case differences in the script tag.
lang|=, Inheritance by inline elements When styling is defined for a block element using lang|= and the lang attribute, the styling should still be picked up by inline elements contained by that block element.
lang|=, Inheritance from an ancestor, block elements When styling is defined for a block element using lang|= but the language is only declared using a lang attribute on an ancestor element, the styling should NOT be picked up.
lang|=, Inheritance from an ancestor, inline elements When styling is defined for an inline element using lang|= but the language is only declared using a lang attribute on an ancestor element, the styling should NOT be picked up.

Snapshot summary, 2011-12-17

All browsers support lang|= selectors as expected.

Unlike :lang, it seems that, for pages served as XML, lang|= selectors do not match class names when the case of the language value in the selector and the class name differs.

No browser matches collapsed script subtags between language and region subtags.

xml|lang |= with xml:lang

Assertion Gecko Presto Trident WebKit Detailed results
[xml|lang|="es"], xml:lang="es" with @namespace An xml|lang|= selector with an @namespace declaration that matches an identical xml:lang attribute value will produce styling.
[xml|lang|="es"], xml:lang="es" with no @namespace An xml|lang|= selector with no @namespace declaration that matches an identical xml:lang attribute value will not produce styling.

Snapshot summary, 2011-12-17

All browsers support xml|lang|= (but only) when used with an @namespace declaration for documents served as XML.

lang= with lang

Assertion Gecko Presto Trident WebKit Detailed results
[lang="es"], lang="es" A lang= value that matches an identical lang attribute value will produce styling.
[lang="es"], lang="es" (xml) [Exploratory test] A lang= value that matches an identical lang attribute value will produce styling in a page served as XML.
[lang="es"], lang="ES" A lang= value will match a lang attribute value regardless of case differences.
[lang="es"], lang="ES" (xml) [Exploratory test] A lang= value will match a lang attribute value regardless of case differences in a page served as XML.
[lang="es"], lang="es-MX" A lang= value will not match a lang attribute value when the latter contains additional subtags.
[lang="es-MX"], lang="es" A lang= value will not match a lang attribute value when the former contains more subtags.
[lang="es"], lang="mx-es" When the lang= value uses a single subtag, it will not match against an attribute value where it appears in a different position.
[lang="en-GB"], lang="en-GB" A lang= value with language and region subtags will match a lang attribute value with the same subtags.
[lang="en-GB"], lang="en-GB-scouse" A lang= value with a multiple subtags will not match a lang attribute value with multiple subtags if the latter has more subtags, even if the first two subtags are the same.
[lang="en-GB"], lang="en-US" A lang= value and a lang attribute value will not match if their region subtags differ.
[lang="az-Arab-IR"], lang="az-Arab-IR" A lang= value with language, script and region subtags will match a lang attribute value with the same language, script and region subtags.
[lang="az-Arab-IR"], lang="az-IR" A lang= value with language, script and region subtags will not match a lang attribute value with the script subtag missing.
[lang="cs-CZ"], lang="cs-Latn-CZ" A lang= value with language and region subtags will not match a lang attribute value with language, script and region subtags.
[lang="az-Arab-IR"], lang="az-arab-IR" A lang= value will match a lang attribute value regardless of case differences in the script tag.
lang=, Inheritance by inline elements When styling is defined for a block element using lang= and the lang attribute, the styling should still be picked up by inline elements contained by that block element.
lang=, Inheritance from an ancestor, block elements When styling is defined for a block element using lang= but the language is only declared using a lang attribute on an ancestor element, the styling should NOT be picked up.
lang=, Inheritance from an ancestor, inline elements When styling is defined for an inline element using lang= but the language is only declared using a lang attribute on an ancestor element, the styling should NOT be picked up.

Snapshot summary, 2011-12-17

All browsers support lang= selectors as expected for HTML pages, but case insensitive matches do not work for any browser in documents served as XML.

xml|lang= with xml:lang

Assertion Gecko Presto Trident WebKit Detailed results
[xml|lang="es"], xml:lang="es" with @namespace An xml|lang= selector with an @namespace declaration that matches an identical xml:lang attribute value will produce styling.
[xml|lang="es"], xml:lang="es" with no @namespace An xml|lang= selector with no @namespace declaration that matches an identical xml:lang attribute value will not produce styling.

Snapshot summary, 2011-12-17

All browsers support xml|lang= when used with a @namespace declaration for documents served as XML.

Styling using the escaped form, xml\:lang, didn't work. This is to be expected, since all the browsers support namespace declarations.