On this page9 sections
  1. Learning Objectives
  2. 1. Inline and Block
  3. 2. Logical Properties Flip Automatically
  4. 3. Shorthands
  5. 4. writing-mode: Vertical Text
  6. Common Beginner Mistakes
  7. Practice Questions
  8. Practice Answers
  9. Key Takeaways

Lecture 030: Logical Properties & Writing Modes

Category6: CSS in Depth
Lecture030 of 057
Estimated video length10 min
TargetCSS3 · any modern browser
LevelIntermediate

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-start and friends
  • Switch direction with dir and direction
  • 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).
PhysicalLogical (for English)
margin-leftmargin-inline-start
margin-rightmargin-inline-end
margin-topmargin-block-start
margin-bottommargin-block-end
widthinline-size
heightblock-size
leftinset-inline-start
text-align: lefttext-align: start

2. Logical Properties Flip Automatically

Example: the same CSS in English and Urdu:

html
<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

css
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

html
<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

  1. What is the inline direction in English?
  2. What's the logical version of padding-left?
  3. Centre a block using a logical property.
  4. Which HTML attribute makes text run right to left?
  5. Which property turns text vertical?

Practice Answers

  1. Left to right.
  2. padding-inline-start
  3. margin-inline: auto;
  4. dir="rtl"
  5. writing-mode (e.g. vertical-rl).

Key Takeaways

  • Inline = along the line; block = the direction lines stack.
  • *-inline-start/end and *-block-start/end replace left/right/top/bottom.
  • Logical properties flip automatically for right-to-left languages.
  • writing-mode makes text vertical.