Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-classes

The :lang() pseudo-class

Reference for the CSS :lang() pseudo-class: match elements by language code, how it inherits from the lang attribute, wildcards, and examples such as quote styles.

The :lang() pseudo-class matches elements by the language of their content. The language comes from the nearest lang attribute on the element or one of its ancestors (or from other document-level information), so :lang(fr) matches a paragraph inside <div lang="fr"> even though the paragraph has no attribute.

Matching is by language range: :lang(en) matches en, en-US and en-GB. This is its advantage over [lang="en"], which matches only the exact attribute value on that element.

CSS
:lang(de) q {
  quotes: "โ€ž" "โ€œ";
}

Try it

Quotes that follow the language

The same <q> element gets each language's quotation marks, and the coloured border is chosen by the inherited language, including en-US matching :lang(en).

Syntax

CSS
:lang( <language-range># ) { }
  • Arguments: one or more language ranges, separated by commas. Quoted strings are allowed and are required for wildcards or when the value is not a valid identifier.
  • Specificity: (0, 1, 0).

Values

Syntax and arguments Description
:lang(en) English in any region: en, en-US, en-GB.
:lang(en-GB) Only British English.
:lang(fr, de) French or German.
:lang("*-CH") Any language with the region Switzerland (extended filtering).
:lang("") Elements whose language is explicitly empty (unknown).

Usage notes

  • Set lang on <html>. :lang() depends on correct language tagging. Setting lang on the root element, then overriding it on foreign-language passages, is also good for accessibility, because screen readers pick the right voice and hyphenation engines use it.
  • Prefer it over [lang|="en"]. The attribute selector checks only the element's own attribute, while :lang() follows inheritance.
  • Typography use. Common targets are quotes, font stacks for scripts such as Arabic or Japanese, text-transform, and hyphens.
  • Case-insensitive. Language tags are not case-sensitive, so :lang(EN) works but lowercase is the convention.
  • Not a translation tool. The pseudo-class only reads what the author declared; it does not detect the actual language.
  • Related but different. Text direction is handled by :dir().

Browser support

:lang() with plain language codes works in every browser. Wildcard ranges and quoted strings are supported in current Chrome, Edge, Firefox and Safari, but test them if you target older versions.