:lang()
Example
[lang='de'] q {
quotes: '„' '“';
}q:lang(de) {
quotes: '„' '“';
}:lang(de) also matches 'de-AT' and elements that inherit German from an ancestor.
Common mistakes
- Using
[lang='en'], which misses child elements and values like 'en-US'. - Styling by language when the
langattribute is missing, so:lang()matches nothing.
Key points
- Language styles use
:lang(xx), which matches inherited languages, not[lang='xx']. - The page sets
langon<html>and on any passage in another language. - Language-specific quotes use
:lang()with thequotesproperty.
Interview questions
What is the difference between :lang() and [lang]?
[lang] checks the attribute on the element itself. :lang() checks the element's language, including inherited ones and subtags.
Does :lang(en) match en-US?
Yes. :lang(en) matches 'en' and any subtag like 'en-US' or 'en-GB'.