:lang
Widely availableSince 201597% of users
Matches elements by language. Use to style different languages differently without adding classes.
What's modern
From web-features, MDN's browser data and our snippets, checked dailyClassicIt has worked everywhere since July 2015.
See how modern your own CSS is.Check your CSS →
Quick example
:lang(en) { font-family: "Arial", sans-serif; }
:lang(ar) { font-family: "Droid Arabic Naskh", sans-serif; }Examples
Style different languages with different fonts
:lang(en) { font-family: "Arial", sans-serif; }
:lang(ar) { font-family: "Droid Arabic Naskh", sans-serif; }
:lang(ja) { font-family: "Noto Sans CJK JP"; }Use different typefaces optimized for each language without adding classes to every element.
Adjust letter-spacing per language
:lang(en) { letter-spacing: 0; }
:lang(ja) { letter-spacing: 0.05em; }
:lang(th) { letter-spacing: 0.1em; }Some languages need different spacing. Set language-specific spacing with :lang().
Combine with lang attribute
<p lang="ar">مرحبا</p>
<p lang="en">Hello</p>
p:lang(ar) { direction: rtl; }The lang attribute on HTML elements controls which :lang() selector matches.
Common pitfalls
- :lang() relies on lang attribute:lang() matches based on the lang attribute (or inherited lang). If your HTML doesn't have lang attributes set correctly, :lang() won't work. Always set lang="en" or appropriate language code on the root element.
- Complex language matching:lang(en) matches both "en", "en-US", "en-GB". This is usually helpful but can be confusing if you expected exact matches only.
- Not the same as data attributesDon't use data-lang attributes with attribute selectors as a substitute. Use the actual lang attribute so screen readers and browsers know the language.
:lang browser support
BaselineWidely availableThis feature is well established and works across many devices and browser versions. It has been available across browsers since 2015.Safe to use without fallbacks.
Usage97%of people can use this3% use a browser without it.
Browsers
1+
1+
3.1+
12+Mobile
18+Android
4+Android
2+iOS