Full answer
A site in several languages needs more than translated text. Each script has its own needs, and CSS can follow the lang attribute to adapt.
Select by language with :lang(). It matches the lang of the element or of its nearest ancestor that has one, so a set lang on the html element and on foreign phrases is the base of everything.
Useful adjustments:
- Font stacks per language. A font made for Latin letters often has no glyphs for Hindi, Arabic or Chinese, and the browser then picks a fallback that may look out of place. Set a suitable stack:
:lang(hi) { font-family: "Noto Sans Devanagari", sans-serif; }. Subset fonts so users download only what they need. - Line height. Scripts with tall marks, such as Devanagari or Thai, and dense scripts, such as Chinese and Japanese, often need a larger
line-heightthan Latin text, around 1.6 to 1.8. - Quotation marks. The
quotesproperty sets the marks used byqand byblockquote::before. German uses „ and “, French uses « and », English uses “ and ”. Without a rule, browsers pick marks for the language of the element. - Line breaking. Chinese and Japanese can break between most characters.
word-break: keep-allkeeps Korean words together.overflow-wrap: anywherehandles long strings in any language. - Letter spacing. Do not add
letter-spacingto scripts that join letters, such as Arabic, because it breaks the joining. - Text size and direction. Use logical properties and the
dirattribute for right-to-left languages, and expect that text length changes by language, so avoid fixed widths for labels.
Test with real text from each language, not with a placeholder.
The Hindi paragraph gets a taller line height. The German quote is drawn with the marks „ and “, and the French one with « and ». Each rule applies only where the language matches.
Check that the font actually has glyphs for the script, or the page will fall back to a different look.
<style>
body { font: 16px/1.5 sans-serif; }
:lang(hi) { line-height: 1.8; }
q:lang(de) { quotes: "„" "“"; }
q:lang(fr) { quotes: "«\00a0" "\00a0»"; }
:lang(ar) { letter-spacing: 0; }
</style>
<p lang="hi" id="hi">नमस्ते दुनिया</p>
<p>German: <q lang="de" id="de">Guten Tag</q></p>
<p>French: <q lang="fr" id="fr">Bonjour</q></p>Run in Chrome 156 (headless) as a page; the snippet is wrapped in a minimal HTML document with doctype, charset and viewport meta tag. Two full runs gave identical results, and the measured values in the answer come from them.
Key points
- :lang() follows the lang attribute.
- Different scripts need different font stacks and line heights.
- quotes sets the quotation marks per language.
- word-break: keep-all and overflow-wrap handle line breaks.
- Do not add letter-spacing to Arabic.
Common mistakes
- Leaving lang off, so no language rules can apply.
- Using one Latin-only font stack for all languages.
- Adding letter-spacing to Arabic text, which breaks the joined letters.
Follow-ups
- What does the quotes property control?
- Why is letter-spacing a problem for Arabic?
Tips
- Say that :lang() depends on the lang attribute, so set it correctly first.
- Give examples for font stacks, line height and quotes.