# :lang()

> The `:lang` CSS pseudo-class selects elements based on the language in their `lang` attribute, allowing styling by language codes like 'en' or 'fr'.

## How do I style text by language with the CSS :lang() selector?

The pseudo-class that applies styles to elements based on the language of the content, as specified by the `lang` attribute. It helps in adapting styles for different languages, like adjusting font styles or text directions for better readability.

- Topic: Pseudo Classes
- Type: pseudo-class
- Browser support: Chrome 1+, Chrome Android 18+, Edge 12+, Firefox 1+, Firefox Android 4+, Safari 3.1+, Safari iOS 2+

## Example

Wrong:

```css
[lang='de'] q {
  quotes: '„' '“';
}
```

Right:

```css
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 `lang` attribute is missing, so `:lang()` matches nothing.

## Key points

- Language styles use `:lang(xx)`, which matches inherited languages, not `[lang='xx']`.
- The page sets `lang` on `<html>` and on any passage in another language.
- Language-specific quotes use `:lang()` with the `quotes` property.

## 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'.

## Related cards

- [\[lang\]](https://wonderium.dev/html/lang.md)
- [quotes](https://wonderium.dev/css/quotes.md)
- [Language of the Website and Content](https://wonderium.dev/a11y/language-of-the-website-and-content.md)
- [i18n](https://wonderium.dev/web/i18n.md)
- [Attribute Selector](https://wonderium.dev/css/attribute-selector.md)

---

- Level: [CSS](https://wonderium.dev/css.md)
- HTML version: https://wonderium.dev/css/lang
- Last updated: 2026-11-25
