2 ms·
:lang (which is actually CSS2 except for the wildcard support) is slightly different than an attribute selector. One difference is that it should handle subtyp
by acdha 10y ago
:lang (which is actually CSS2 except for the wildcard support) is slightly different than an attribute selector.
One difference is that it should handle subtypes seamlessly - e.g. :lang(es) would match <div lang="es-mx"> without the developer having to remember to use [lang*=] or consider whether their expression could match other languages (e.g. did your attempt to select Canadian English (lang=en-ca) match Catalan (lang=ca) or vice versa?).
The main reason I use :lang, however, is for inheritance:
<p lang="zh">
We don't want <b>Chinese text to be displayed in bold</b>
</p>
b:lang(zh) { font-weight: normal !important; } will reliably match <b> every time. [lang="zh"] won't without additional work writing and testing selectors and nested content is easy to get wrong in complex documents. I use things like q:lang() for quotations where it's really nice to be consistent across levels of embedded quoting.