CSS Portal

:lang() CSS Pseudo Class

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The :lang() pseudo-class in CSS is used to select elements based on their language attribute, typically defined in the HTML using the lang attribute. This allows developers to apply specific styles to content written in different languages, which is especially useful for multilingual websites or documents that require typographic or stylistic adjustments depending on the language of the text. By using :lang(), you can tailor the appearance of text without manually adding extra classes or identifiers, making your CSS more semantic and maintainable.

The :lang() pseudo-class matches the language of an element and its descendants. It accepts a language code as its argument, following the standard BCP 47 format, such as en for English, fr for French, or es-ES for Spanish as used in Spain. If an element has a language attribute that starts with the specified code, the selector applies. For instance, <p lang="en-US">Hello</p> will match :lang(en), because "en-US" starts with "en".

A common use case is adjusting typography or punctuation rules for different languages. For example, certain languages may require larger line spacing or specific quotation marks. You can combine :lang() with other selectors and CSS properties, such as font-family or quotes, to ensure readability and proper formatting.

Here is a simple example demonstrating its usage:

<p lang="en">Hello, world!</p>
<p lang="fr">Bonjour le monde!</p>
p:lang(en) {
  font-family: Arial, sans-serif;
  color: blue;
}

p:lang(fr) {
  font-family: "Times New Roman", serif;
  color: red;
}

In this example, English paragraphs will appear in blue Arial, while French paragraphs will appear in red Times New Roman.

The :lang() pseudo-class is also particularly useful in combination with internationalization of websites, allowing developers to provide language-specific styles without additional markup. Moreover, it can help with accessibility, as screen readers and other assistive technologies can benefit from semantically correct language tagging.

A practical tip is that :lang() can match any descendant elements if they inherit the language from their parent, which reduces the need to set the lang attribute on every single element individually. This makes your CSS cleaner and your HTML simpler.

Syntax

:lang(<language-code> [,<language-code> ]*)
  /* ... */
}

Values

  • <language>represents the language you want to target, such as: en - English; ru - Russian; de - German fr - French; it - Italian etc

Example

<div class="content">
<div lang="en">
<p>This is an English paragraph. It uses standard quotes.</p>
</div>

<hr>

<div lang="fr">
<p>C'est un paragraphe en français. Il utilise des guillemets.</p>
</div>

<hr>

<div lang="ja">
<p>これは日本語の段落です。縦書きも可能です。</p>
</div>
</div>
/* Styling for English */
:lang(en) {
color: #2c3e50;
font-family: "Georgia", serif;
}

/* Styling for French */
/* French typography often uses different quotes (« ») */
:lang(fr) {
color: #c0392b;
font-style: italic;
}

:lang(fr) p::before {
content: "« ";
}

:lang(fr) p::after {
content: " »";
}

/* Styling for Japanese */
:lang(ja) {
color: #2980b9;
font-family: "Hiragino Kaku Gothic Pro", "Meiryo", sans-serif;
line-height: 1.8;
}

Browser Support

The following information will show you the current browser support for the CSS :lang() pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS psuedo class.

This psuedo class is supported by all modern browsers.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!