✍️ writing-mode β€” Controlling Text Flow Direction in CSS

🌐 What is writing-mode?

writing-mode is a CSS property that controls the direction in which text and inline content flow. Instead of always flowing left-to-right horizontally, you can rotate the writing flow to vertical layouts β€” common in East Asian typography, banners, labels, and dashboards.

>>β€œwriting-mode lets you rotate the flow of text β€” not the element itself.”

Note

βœ” Fully supported in all modern browsers
βœ” Works with text, inline elements, tables, and block elements
βœ” Essential for vertical layouts and creative UI designs

🎯 Why Use writing-mode?

  • Create vertical navigation menus
  • Design East-Asian vertical text (Chinese, Japanese, Korean)
  • Make badges or labels in dashboards
  • Rotate text without using transforms
  • Control block & inline flow direction independently

πŸ“Œ Syntax

writing-mode Syntax

writing-mode: horizontal-tb | vertical-rl | vertical-lr;

πŸ“ Values Explained

ValueMeaning
horizontal-tb (default)Text flows left β†’ right, lines stack top β†’ bottom
vertical-rlText flows top β†’ bottom, lines stack right β†’ left
vertical-lrText flows top β†’ bottom, lines stack left β†’ right

Note

πŸ’‘ In vertical writing modes, β€œline” means vertical line of characters.

πŸ§ͺ Example 1 β€” Vertical Text (Right β†’ Left)

vertical-rl Example

.vertical {
  writing-mode: vertical-rl;
  border: 1px solid #ccc;
  padding: 10px;
}

Text flows downward, and each line moves toward the left edge.

πŸ§ͺ Example 2 β€” Vertical Text (Left β†’ Right)

vertical-lr Example

.vertical-left {
  writing-mode: vertical-lr;
  border: 1px solid #ccc;
  padding: 10px;
}

Similar to Japanese manga layout β€” text flows vertically but advances to the right.

πŸ§ͺ Example 3 β€” Horizontal (Normal)

horizontal example

.horizontal {
  writing-mode: horizontal-tb;
}

πŸ“ Writing Mode Effects

Writing mode changes how block and inline axes behave:

ModeInline AxisBlock Axis
horizontal-tbLeft β†’ RightTop β†’ Bottom
vertical-rlTop β†’ BottomRight β†’ Left
vertical-lrTop β†’ BottomLeft β†’ Right

Note

🧠 This affects flexbox, grid, margin collapsing, and text alignment behavior.

🎨 Example β€” Vertical Sidebar Navigation

Vertical Nav

.side-nav {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-size: 1.2rem;
  background: #111;
  color: white;
  padding: 20px;
  height: 100vh;
}

text-orientation: upright keeps letters upright rather than rotated.

🧠 text-orientation (Important Partner Property)

text-orientation Example

.vertical {
  writing-mode: vertical-rl;
  text-orientation: upright;
}

Ensures Latin letters remain upright instead of rotated sideways.

πŸ“± Example β€” Vertical Labels in Dashboard UI

Dashboard Labels

.label {
  writing-mode: vertical-lr;
  text-orientation: upright;
  background: #f4f4f4;
  padding: 10px;
  border-radius: 6px;
}

🧩 writing-mode with Flexbox & Grid

Writing mode changes the meaning of block/inline sizes:

Flexbox Example

.flex {
  display: flex;
  writing-mode: vertical-rl;
  gap: 10px;
}

Now β€œrow” becomes vertical and β€œcolumn” becomes horizontal!

⚠️ Common Mistakes

  • ❌ Using writing-mode to rotate text when transform: rotate() is better
  • ❌ Forgetting text-orientation when using Latin characters vertically
  • ❌ Expecting writing-mode to work on background-position or non-text items
  • ❌ Misunderstanding block/inline axis changes in flex & grid

Note

πŸ’‘ Use writing-mode for flow direction, not decorative rotation.

πŸ”₯ Summary

writing-mode lets you control the direction of text flow, enabling powerful layout possibilities from vertical headers to complex Asian typography. Combined with text-orientation, it opens new creative options for modern UI and design systems.

>>β€œwriting-mode doesn’t rotate text β€” it rotates the entire writing flow.”

Learn more β†’MDN Docs πŸ“˜