CSS Reference ยท Typography
The writing-mode property
Reference for the CSS writing-mode property: horizontal-tb, vertical-rl, vertical-lr and the sideways values, with live examples and logical-property notes.
The writing-mode property sets whether lines of text run horizontally or vertically, and in which direction new lines (blocks) are stacked. Horizontal text is the default. Vertical modes are used for East Asian languages such as Japanese, Chinese and Mongolian, but also for design effects like a rotated label along the side of a card.
Changing the mode swaps the meaning of the two layout axes. In a vertical mode, the inline direction runs top to bottom, and the block direction runs horizontally. That is why modern CSS uses logical properties such as inline-size and margin-block-start: they adapt automatically.
.side-label { writing-mode: vertical-rl; }
Try it
In the two vertical boxes, the Latin letters are rotated a quarter turn clockwise and the lines start at the top. In vertical-rl the first line is at the right and the next lines go to the left; in vertical-lr they go to the right.
Syntax
writing-mode: horizontal-tb | vertical-rl | vertical-lr | sideways-rl | sideways-lr;
| Initial value | horizontal-tb |
| Applies to | all elements except table row groups, table column groups, table rows, table columns, ruby base containers and ruby annotation containers |
| Inherited | yes |
| Animatable | no |
| Computed value | as specified |
Values
| Value | Description |
|---|---|
horizontal-tb |
Lines run horizontally; blocks stack top to bottom. Default. |
vertical-rl |
Lines run vertically; blocks stack from right to left. The standard mode for Japanese and Chinese vertical text. |
vertical-lr |
Lines run vertically; blocks stack from left to right. Used for Mongolian. |
sideways-rl |
Like vertical-rl, but all glyphs are set sideways (rotated), like a rotated horizontal line. Newer; check a compatibility table. |
sideways-lr |
Sideways text where lines read from bottom to top. Newer; check a compatibility table. |
Usage notes
- Latin text in vertical modes. Characters from scripts without vertical forms are rotated sideways by default.
text-orientationcan set them upright instead (text-orientation: upright), which suits short code-like labels. - Width and height swap meaning for flow. In vertical modes,
inline-sizeis the physical height. Settingheighton the container, as in the demo, is what limits the line length. - Use logical properties.
margin-inline,padding-block,inline-sizeand friends follow the writing mode;margin-leftdoes not. Seelogical properties. - Rotated labels. For a simple sideways label,
writing-mode: vertical-rlplustransform: rotate(180deg)makes it read bottom to top.sideways-lrdoes this without a transform where supported. - Flex and grid. The main axis of a flex row follows the inline direction, so a row in a vertical mode runs downward.
- Changing it on the root. Setting it on
htmlchanges the whole page and also the direction of scrolling; test thoroughly. - Readability. Do not use vertical text for long English passages. It is slow to read.
Browser support
horizontal-tb, vertical-rl and vertical-lr are supported in all current browsers. The sideways-* values are newer and not available everywhere, so check a compatibility table.
Related
directionโ inline direction within a modetext-orientationโ glyph orientation in vertical textlogical propertiesโ properties that follow the modemargin-inlineโ a logical margin- Lesson: Writing Modes and Logical Properties