On this page9 sections
Lecture 030: Logical Properties & Writing Modes
| Category | 6: CSS in Depth |
| Lecture | 030 of 057 |
| Estimated video length | 10 min |
| Target | CSS3 · any modern browser |
| Level | Intermediate |
English reads left to right; Urdu and Arabic read right to left; Japanese can run top to bottom. Logical properties describe spacing by the direction of the text ("start", "end") instead of fixed sides ("left", "right"), so one stylesheet works in every language.
Learning Objectives
- Understand the inline and block directions
- Use
margin-inline,padding-block,inset-inline-startand friends - Switch direction with
diranddirection - Rotate text with
writing-mode
1. Inline and Block
- Inline direction: the way a line of text runs (left → right in English).
- Block direction: the way new lines stack (top → bottom).
| Physical | Logical (for English) |
|---|---|
margin-left | margin-inline-start |
margin-right | margin-inline-end |
margin-top | margin-block-start |
margin-bottom | margin-block-end |
width | inline-size |
height | block-size |
left | inset-inline-start |
text-align: left | text-align: start |
2. Logical Properties Flip Automatically
Example: the same CSS in English and Urdu:
<style>
.note {
border-inline-start: 5px solid #1971c2; /* left in English, right in Urdu */
padding-inline-start: 12px;
margin-block: 10px;
text-align: start;
background: #e7f5ff;
padding-block: 8px;
}
</style>
<p class="note" dir="ltr">An English note with its border on the left.</p>
<p class="note" dir="rtl" lang="ur">اردو نوٹ، جس کی لکیر دائیں طرف ہے۔</p>With border-left, the Urdu note would have its border on the wrong side.
3. Shorthands
margin-inline: auto; /* left and right (centre a block) */
padding-block: 1rem 2rem; /* top 1rem, bottom 2rem */
inset-inline: 0; /* left: 0; right: 0 */4. writing-mode: Vertical Text
Example
<style>
.row { display: flex; gap: 14px; align-items: flex-start; }
.v { writing-mode: vertical-rl; background: #fff3bf; padding: 8px; height: 140px; }
.s { writing-mode: sideways-lr; background: #d3f9d8; padding: 8px; height: 140px; }
</style>
<div class="row">
<div class="v">vertical-rl text</div>
<div class="s">sideways-lr label</div>
<p>Vertical text is useful for table headers, side labels and East Asian languages.</p>
</div>In a vertical writing mode the inline direction runs down the page, and logical properties follow it.
Common Beginner Mistakes
1. Hard-coding left and right on a multilingual site. Use inline-start and inline-end.
2. Setting direction: rtl in CSS instead of dir in HTML. Direction is part of the content; put dir="rtl" on the element.
3. Mixing physical and logical properties on the same element. It quickly becomes confusing.
Practice Questions
- What is the inline direction in English?
- What's the logical version of
padding-left? - Centre a block using a logical property.
- Which HTML attribute makes text run right to left?
- Which property turns text vertical?
Practice Answers
- Left to right.
padding-inline-startmargin-inline: auto;dir="rtl"writing-mode(e.g.vertical-rl).
Key Takeaways
- Inline = along the line; block = the direction lines stack.
*-inline-start/endand*-block-start/endreplace left/right/top/bottom.- Logical properties flip automatically for right-to-left languages.
writing-modemakes text vertical.