The :lang() pseudo-class applies styles based on the language of an element, set via the lang attribute or inherited from a parent.
01
lang attr
Language code.
02
:lang(en)
By language.
03
Multilingual
Mixed content.
04
Regional
en-US, en-GB.
05
Inheritance
From html lang.
06
Quotes
Locale glyphs.
Fundamentals
Introduction
The :lang() selector in CSS allows you to apply styles based on the language of an HTML element. This is particularly useful for multilingual websites where different languages need distinct typography or visual treatment.
It improves accessibility and enhances the user experience by adapting presentation to each language’s conventions.
Definition and Usage
Write :lang(language-code) with a BCP 47 language tag such as en, fr, or zh-Hans. The selector matches elements whose effective language equals or starts with that code.
💡
Beginner Tip
Set lang on the <html> element for the page default, then override on individual elements: <p lang="fr">. Child elements inherit the parent’s language unless they specify their own.
Foundation
📝 Syntax
The syntax for the :lang() pseudo-class is:
syntax.css
:lang(language-code){/* CSS properties */}
The function accepts language codes that correspond to the lang attribute in HTML. You can also list multiple codes: :lang(en, fr).
Language is determined by the element’s lang attribute or inherited from ancestors.
:lang(en) matches en, en-US, and en-GB.
:lang(en-US) matches only U.S. English, not generic en.
Combine with elements: h1:lang(fr), blockquote:lang(de).
Always set lang in HTML for accessibility — CSS relies on it.
Related Selectors
[lang] attribute selector — matches any element with a lang attribute
[lang="fr"] — exact attribute match (no inheritance)
:dir(rtl) — styles based on text direction (right-to-left)
::before / ::after — add language labels with generated content
font-family property — often paired with :lang() for script-appropriate fonts
Cheat Sheet
⚡ Quick Reference
Question
Answer
Selector type
Functional pseudo-class
Syntax
:lang(code)
Data source
lang attribute (with inheritance)
:lang(en) matches
en, en-US, en-GB, etc.
Common use
Multilingual typography and quotes
Browser support
All browsers
Context
When to Use :lang()
:lang() is ideal for internationalized content:
Multilingual blogs — Style paragraphs differently when lang="fr" or lang="es" is set.
Font selection — Use serif fonts for Latin scripts and system fonts for CJK languages.
Quotation marks — Apply language-appropriate quote glyphs with the quotes property.
Regional spelling hints — Highlight U.S. vs British English with :lang(en-US).
Language badges — Combine with ::before to show a small language label.
Preview
👀 Live Preview
Three paragraphs with different lang attributes styled by :lang():
This is an English paragraph.
Ceci est un paragraphe en français.
Este es un párrafo en español.
Hands-On
Examples Gallery
Practice :lang() with multilingual paragraphs, scoped selectors, regional variants, and quote styling.
📜 Core Patterns
Style content based on language codes.
Example 1 — Style English, French, and Spanish
Apply distinct color and font-family to paragraphs in three languages.
lang-multilingual.html
<style>:lang(en){color:#1d4ed8;font-family:system-ui, sans-serif;}:lang(fr){color:#b91c1c;font-family:Georgia, serif;}:lang(es){color:#15803d;font-family:"Segoe UI", sans-serif;}</style><plang="en">This is an English paragraph.</p><plang="fr">Ceci est un paragraphe en français.</p><plang="es">Este es un párrafo en español.</p>
The :lang() pseudo-class matches elements based on their language, as indicated by the lang attribute or inherited from a parent. You pass a language code like en, fr, or es inside the parentheses.
From the element's own lang attribute, or inherited from an ancestor such as html lang="en". An element matches :lang(en) if its effective language is English.
:lang(en) matches any English variant including en-US and en-GB. :lang(en-US) matches only U.S. English specifically.
Yes. Combine them like p:lang(fr) or h1:lang(es) to target specific elements in a given language.
Yes. :lang() is supported in all modern and legacy browsers. It is a long-standing CSS feature for internationalization.