Lesson 26 of 50
cssLogical Properties & Writing Modes
7 mins
Course progress52%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 26 of 50
css7 mins
Keep these ideas in mind as you work through the lesson.
Logical properties let you write direction‑agnostic CSS, which is essential for multilingual sites that support right‑to‑left (RTL) scripts.
| Physical | Logical |
|---|---|
margin-left | margin-inline-start |
margin-right | margin-inline-end |
margin-top | margin-block-start |
margin-bottom | margin-block-end |
ltr or rtl) changes, the logical properties automatically map to the correct physical side..card {
padding-inline: 1.5rem; /* left in LTR, right in RTL */
padding-block: 1rem; /* top & bottom stay the same */
}
writing-mode controls the flow of text:
horizontal-tb – default (left‑to‑right horizontally, top‑to‑bottom).vertical-rl – characters flow top‑to‑bottom, columns progress right‑to‑left (common in Japanese).vertical-lr – top‑to‑bottom, columns left‑to‑right.<body dir="ltr"> … </body>
<body dir="rtl"> … </body>
/* Global layout uses logical margins */
.container { margin-inline: auto; max-width: 80ch; }
The container stays centered regardless of direction.
When you set direction on an element, also set lang attribute (<html lang="ar" dir="rtl">). Screen readers use lang for proper pronunciation.