skip to content

What does writing-mode: vertical-rl do to an element's block and inline axes, and which physical dimension does inline-size then control?

level: middleimportance: should knowfreq 28%

answer

  1. vertical text, blocks flow right to left
  2. the two axes trade orientation
  3. inline-size becomes a height
  4. scrolling turns horizontal
  5. rotated table headers without a transform

basics

~10 s

writing-mode: vertical-rl makes text run top-to-bottom in lines that stack right-to-left. The inline axis becomes vertical and the block axis horizontal, so inline-size sets the element's rendered height and block-size its width.

solid answer

~40 s

`writing-mode: vertical-rl` rotates the whole flow: text advances downward within a line, and successive lines stack from right to left. That means the inline axis is now vertical and the block axis horizontal. Consequently `inline-size` controls the element's rendered height, `block-size` its width, `block-start` is the right edge and `block-end` the left, while `inline-start` is the top edge for `direction: ltr`. `vertical-lr` is the same rotation with lines stacking left-to-right instead, so `block-start` is the left edge. The property is inherited, so setting it on a container flips every descendant's layout, and paragraphs inside will overflow toward the bottom rather than the right. Beyond CJK typography the common uses are rotated table headers and chart axis labels, where `writing-mode` plus `text-orientation` avoids a transform.

code

css · 7 lines
css
.vertical-panel {
  writing-mode: vertical-rl;
  max-inline-size: 30em;   /* caps the column height */
  block-size: 100%;        /* fills available width */
  padding-inline-start: 1rem; /* gutter at the top edge */
  border-block-start: 2px solid; /* rule on the right edge */
}

go deeper

for a junior

Know that writing-mode: vertical-rl makes text run downward and that it is a real layout change, not a visual rotation. Recognising it on rotated table headers is enough at this level.

for a middle

Be able to state the axis swap precisely — inline becomes vertical, block becomes horizontal, inline-size becomes a height — and explain that direction and writing-mode together resolve every logical property.

for a senior

Demonstrate the operational consequences: scrolling turns horizontal, percentages resolve against a vertical inline size, and the property inherits into components that were never designed for it.

for a principal

Decide whether vertical writing modes are actually in scope for the product before paying the design and QA cost, and set the boundary — for instance logical properties everywhere, but vertical mode supported only on specific surfaces.

## What the value actually says The `writing-mode` keyword names two things at once: the direction text advances within a line, and the direction lines stack. - `horizontal-tb` — text horizontal, lines stack top-to-bottom. The initial value. - `vertical-rl` — text vertical (top-to-bottom), lines stack right-to-left. - `vertical-lr` — text vertical, lines stack left-to-right. So `vertical-rl` reads as "vertical text, blocks flow right-to-left". The first line of a vertical Japanese page sits against the right edge and each subsequent line is added to its left, which is exactly how a printed novel in that language is set. ## The axis consequences Under `vertical-rl`: | Logical | Physical | |---|---| | inline-start | top | | inline-end | bottom | | block-start | right | | block-end | left | | inline-size | rendered height | | block-size | rendered width | `direction: rtl` combined with `vertical-rl` flips only the inline pair, putting inline-start at the bottom. This is where the payoff of logical properties becomes concrete. A component written as: ```css .note { border-inline-start: 3px solid; padding-inline-start: 1rem; max-inline-size: 40ch; } ``` keeps its meaning — a rule bar at the start of each line, a gutter after it, and a capped line length — whether the bar renders on the left, the right, the top or the bottom. The physical equivalent would draw the bar on the left in every writing mode, which is simply wrong for a vertical column. ## Things that surprise people the first time **Overflow and scrolling rotate too.** In `vertical-rl` the block direction is right-to-left, so a long document's scroll progress runs leftward and the scroll container gains a horizontal scrollbar rather than a vertical one. Code that assumes "long content means vertical scrolling" breaks. **The property inherits.** Setting `writing-mode: vertical-rl` on a wrapper flips the entire subtree, including components that were never designed for it. Scope it deliberately. **Percentage sizing follows the flow, not the screen.** Percentages on `padding` and `margin` resolve against the containing block's inline size, and in a vertical writing mode that inline size is a *height*. A `padding-inline: 5%` that looked stable horizontally can behave very differently once rotated. **Latin text needs `text-orientation`.** In a vertical mode, Latin characters are rotated sideways by default (`text-orientation: mixed`). `text-orientation: upright` keeps each glyph upright and stacks them, which is what you want for short Latin runs inside CJK text but not for whole sentences. ## The non-CJK use case Most engineers meet `writing-mode` not through Japanese typography but through rotated labels: ```css th.rotated { writing-mode: vertical-rl; text-orientation: mixed; } ``` Compared with `transform: rotate(-90deg)`, this keeps the text *in layout*: the cell reserves real space for the rotated run, the text wraps and is selectable normally, and there is no need to compensate for a transformed box that no longer affects its parent's size. That difference — layout participation versus a visual-only transform — is the point an interviewer is usually probing. ## Relationship to direction `writing-mode` and `direction` are orthogonal and both inherited. `writing-mode` decides the orientation of the two axes; `direction` decides which end of the inline axis is the start. You need both to fully resolve any logical property, which is why the mapping question is never answerable from one of them alone.

  • How does vertical-lr differ from vertical-rl?
    Only in how lines stack. Both run text downward, but `vertical-lr` stacks successive lines left-to-right, so `block-start` is the left edge and block progression matches the scroll direction Western readers expect. `vertical-rl` stacks right-to-left, putting `block-start` on the right — the traditional setting for Japanese and Chinese.
  • Why prefer writing-mode over transform: rotate() for a rotated table header?
    `writing-mode` keeps the text in normal layout: the cell reserves the space the rotated run occupies, the text wraps and can be selected, and the parent sizes around it. `transform` is a visual-only operation applied after layout, so the untransformed box still dictates size and you end up hand-tuning widths and offsets to compensate.
  • What does text-orientation: upright do inside a vertical writing mode?
    It stops the browser rotating Latin and other horizontal-script glyphs sideways and instead sets each character upright, stacking them down the line. The default `mixed` rotates such runs 90 degrees while keeping CJK glyphs upright, which is correct for embedded Latin words but wrong when you want each letter standing.

saying these in an interview costs you the question

  • Says vertical-rl only rotates the text visually
  • Thinks writing-mode affects only text, not the box axes
  • Assumes long content still scrolls vertically in vertical-rl
  • Confuses vertical-rl with direction: rtl
  • Believes writing-mode does not inherit to children

context