Lesson 45 of 50
cssLogical CSS for Internationalization
7 mins
Course progress90%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 45 of 50
css7 mins
Keep these ideas in mind as you work through the lesson.
Internationalisation (i18n) goes beyond translation – the layout must adapt to reading direction (LTR vs RTL) and sometimes to vertical scripts.
dir attribute – tells the browser the base direction (dir="rtl" or dir="ltr").margin-inline-start, padding-block-end, etc.unicode-bidi – controls how mixed‑direction text is displayed (unicode-bidi:plaintext).writing-mode – for vertical scripts (vertical-rl, vertical-lr).<nav class="nav" dir="ltr">
<a href="#" class="nav__link">Home</a>
<a href="#" class="nav__link">About</a>
</nav>
.nav { display:flex; gap:1rem; }
/* When the parent switches to rtl, margins adapt automatically */
.nav__link { margin-inline-start:1rem; }
html[lang="ar"] { direction:rtl; }
html[lang="en"] { direction:ltr; }
lang attribute on <html> flips the whole layout.Prefer SVG icons that can be mirrored with transform:scaleX(-1) when dir:rtl.
[dir="rtl"] .icon { transform:scaleX(-1); }
lang attribute on the <html> element – it guides screen readers.unicode-bidi: plaintext on blocks that contain mixed LTR/RTL text to preserve the intended order.margin-left:20px for a UI that might be mirrored. Use margin-inline-start instead. This prevents UI breakage when the site is viewed in Arabic, Hebrew, or Persian.:root { --spacing-inline:1rem; }
[dir="rtl"] { --spacing-inline:2rem; }
.element { margin-inline-start: var(--spacing-inline); }
Now you can tweak the spacing per direction without rewriting every selector.