CSS Writing Modes
In this page:
selector {
writing-mode: horizontal-tb | vertical-rl | vertical-lr;
}
Introduction to Writing Modes
The writing-mode property specifies whether lines of text are laid out horizontally or vertically, and the direction in which blocks progress across the container.
- Use writing-mode: vertical-rl to rotate English headers elegantly on your side panels.
- Accepted values:
- horizontal-tb — horizontal lines flowing top to bottom (default)
- vertical-rl — vertical lines flowing right to left
- vertical-lr — vertical lines flowing left to right
- sideways-rl | sideways-lr — rotated horizontal text
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Introduction to Writing Modes
<style>
p {
writing-mode: vertical-rl;
}
</style>
<p>Text lays out vertically instead of horizontally</p>
Horizontal-TB Mode
The horizontal-tb (top-to-bottom) mode is the default setting for Western languages. Text runs horizontally from left to right, and paragraph blocks stack vertically from top to bottom.
- Always specify this default mode inside your global resets to ensure layout consistency.
- Accepted values:
- horizontal-tb — default, horizontal lines, blocks stack top to bottom
- writing-mode: vertical-rl — for comparison
- direction: ltr | rtl — inline direction within it
- text-align: start — follows the writing direction
Example: Horizontal-TB Mode
<style>
p {
writing-mode: horizontal-tb;
}
</style>
<p>Default: left-to-right text, blocks stack top to bottom</p>
Vertical-RL and Vertical-LR Modes
The vertical-rl (right-to-left) and vertical-lr (left-to-right) modes rotate text to run vertically from top to bottom. They are essential for East Asian vertical layouts and can be used to create stylish design features in Western layouts.
- Use vertical-lr for design-centric sidebars to align text along the left edge of the page cleanly.
- Accepted values:
- horizontal-tb — default, horizontal lines, blocks flow top to bottom
- vertical-rl — vertical lines, blocks flow right to left
- vertical-lr — vertical lines, blocks flow left to right
- sideways-rl — like vertical-rl but glyphs rotated sideways (limited support)
- sideways-lr — like vertical-lr but glyphs rotated sideways (limited support)
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Vertical-RL and Vertical-LR Modes
<style>
.rl { writing-mode: vertical-rl; }
.lr { writing-mode: vertical-lr; }
</style>
<p class="rl">Vertical, right to left</p>
<p class="lr">Vertical, left to right</p>
Text Orientation Options
When you rotate Western text vertically, the browser rotates the letters sideways by default. The text-orientation property allows you to change this behavior, letting you display letters upright in vertical layouts.
- Use text-orientation: upright to keep vertical numbers or words easily readable for Western readers.
- Accepted values:
- text-orientation: mixed — default, Latin glyphs rotated
- text-orientation: upright — every glyph upright
- text-orientation: sideways — all glyphs rotated
- writing-mode: vertical-rl | vertical-lr — text-orientation only applies in vertical modes
- inherit | initial | unset | revert — CSS-wide keywords accepted by every property
Example: Text Orientation Options
<style>
p {
writing-mode: vertical-rl;
text-orientation: upright;
}
</style>
<p>Letters stay upright instead of rotated sideways</p>
Combining Writing Modes with Grid Layouts
You can combine custom writing modes with grid layouts to build complex, multi-directional web designs (such as horizontal grids next to vertical sidebars) cleanly.
- Use Flexbox to easily align and center your rotated vertical elements.
- Accepted values:
- writing-mode: vertical-rl — swaps the inline and block axes of the grid
- grid-template-columns — columns follow the inline axis
- grid-template-rows — rows follow the block axis
- inline-size | block-size — logical sizing
Example: Combining Writing Modes with Grid Layouts
<style>
.layout {
display: grid;
grid-template-columns: auto 1fr;
gap: 8px;
}
.sidebar {
writing-mode: vertical-rl;
background: steelblue;
color: white;
padding: 8px;
}
.layout > div:not(.sidebar) {
background: #ddd;
padding: 8px;
}
</style>
<div class="layout">
<div class="sidebar">Vertical sidebar</div>
<div>Horizontal main content</div>
</div>
- Using transform: rotate to rotate text blocks instead of using native, accessible writing-mode properties.
- Attempting to set text-orientation upright inside standard horizontal layouts, which is ignored.
- Forgetting that changing writing modes automatically rotates your block and inline axes, which can break layout dimensions.
- The writing-mode property specifies if lines of text are laid out horizontally or vertically.
- Use vertical-rl and vertical-lr to rotate text blocks to run vertically on your page.
- Control character orientation inside vertical layouts using the text-orientation property, and pair with Flexbox for clean vertical alignments.
Standard CSS writing modes and text orientation properties are supported natively by all modern web browsers.
Chapter Quiz — Complete all 25 topics to unlock
0/25 topics done
Complete these topics first:
- CSS Container Queries
- CSS Subgrid
- CSS Logical Properties
- CSS Logical Sizing
- CSS Writing Modes
- CSS Aspect Ratio
- CSS Object Fit
- CSS object-position
- CSS Masking
- CSS Math Functions
- CSS Motion Path
- CSS @supports
- CSS @property
- CSS At-Rules
- CSS Cursor
- CSS Will Change
- CSS User Interface
- CSS Print Styles
- CSS Pagination (Print)
- CSS Dark Mode
- CSS Accessibility
- CSS Performance
- CSS Preprocessors
- CSS Frameworks Overview
- CSS Interview Prep