Sub topic 3
The block and inline axes
This chapter assumes you know the box model, the width, height, margin and padding properties, and the lang and dir HTML attributes. It also assumes you have seen writing-mode at least once. By the end you should be able to name the two axes for any combination of writing-mode and direction, and say which physical edge each end of an axis points to.
Two axes instead of two dimensions
Physical CSS describes a box with horizontal and vertical terms: width, height, left, right, top, bottom. Logical CSS replaces them with two axes that depend on how text flows:
- The inline axis is the direction text runs along a line. In English, it runs left to right.
- The block axis is the direction new lines, paragraphs and block boxes stack. In English, it runs top to bottom.
The two axes are always perpendicular. Both are defined by the element's own writing-mode and direction, never by the screen. Every logical property in the chapters that follow is a name for a position on one of these axes, so this model is the foundation for the rest.
Each axis has two ends:
- inline-start and inline-end are the two ends of the inline axis.
- block-start and block-end are the two ends of the block axis.
"Start" is where content begins in that direction. "End" is where it finishes.
What decides the axes
Two properties set the axes.
writing-mode chooses the block flow direction, and therefore which physical axis is the block axis:
horizontal-tb: lines are horizontal, and blocks stack top to bottom. This is the default, used by English, Arabic, Hebrew and most other scripts.vertical-rl: lines are vertical, and blocks stack from right to left. Traditional Japanese, Chinese and Korean typesetting use this.vertical-lr: lines are vertical, and blocks stack from left to right. Traditional Mongolian uses this.
direction (or the dir attribute in HTML) chooses which way the inline axis points: ltr or rtl. It never changes which physical axis is inline. It only reverses the inline start and end.
| writing-mode | direction | Inline axis runs | Block axis runs |
|---|---|---|---|
| horizontal-tb | ltr | left to right | top to bottom |
| horizontal-tb | rtl | right to left | top to bottom |
| vertical-rl | ltr | top to bottom | right to left |
| vertical-rl | rtl | bottom to top | right to left |
| vertical-lr | ltr | top to bottom | left to right |
| vertical-lr | rtl | bottom to top | left to right |
Read the table by columns. The block column changes only when writing-mode changes. The inline column changes with both properties. In a vertical mode, direction: rtl means text starts at the bottom and reads upward.
Working out the sides
To find the physical edge behind a logical name, follow three steps.
- Find the physical axis of the inline direction from
writing-mode. Horizontal forhorizontal-tb, vertical otherwise. - Find which end of that axis is inline-start from
direction. In a horizontal mode,ltrstarts at the left andrtlstarts at the right. In a vertical mode,ltrstarts at the top andrtlstarts at the bottom. - Find block-start from
writing-mode. It is the top forhorizontal-tb, the right forvertical-rl, and the left forvertical-lr.
Take writing-mode: vertical-rl; direction: ltr:
- Inline axis is vertical, and inline-start is the top.
- Block axis is horizontal, and block-start is the right.
- So inline-end is the bottom, and block-end is the left.
Notice that block-start is on the right even though the language is left-to-right in nature. The script's block progression decides this, not the language's inline direction.
Sizes follow the axes too
The sizing properties that match the axes are:
inline-sizeis the box's extent along the inline axis.block-sizeis the box's extent along the block axis.
In horizontal text, inline-size is width and block-size is height. In a vertical mode they swap:
.vertical {
writing-mode: vertical-rl;
inline-size: 20rem;
block-size: 10rem;
}Here the inline axis is vertical, so inline-size: 20rem makes the element 20rem tall. The block axis is horizontal, so block-size: 10rem makes it 10rem wide. If you had written width: 20rem; height: 10rem, you would get the opposite shape. That is correct for a diagram that must stay landscape, but it is wrong for a text column that should grow with its text.
The same idea gives you the min and max variants: min-inline-size, max-inline-size, min-block-size and max-block-size. The next chapters cover them in detail. For now, remember that a value follows the axis, not the screen.
Seeing the axes in a browser
This page puts the same box in three writing modes. The outline stays physical, and the text and sizes follow the axes.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Block and inline axes</title>
<style>
.demo {
display: flex;
gap: 1rem;
align-items: flex-start;
}
.box {
inline-size: 12rem;
block-size: 8rem;
padding: 0.5rem;
outline: 2px solid steelblue;
}
.vrl { writing-mode: vertical-rl; }
.vlr { writing-mode: vertical-lr; }
</style>
</head>
<body>
<div class="demo">
<div class="box">horizontal-tb: inline-size is the width.</div>
<div class="box vrl">vertical-rl: inline-size is the height.</div>
<div class="box vlr">vertical-lr: inline-size is the height.</div>
</div>
</body>
</html>In the first box, 12rem is the width. In the other two, 12rem is the height and 8rem is the width. The two vertical boxes look identical in size. They differ only in where block-start is, which matters once lines wrap onto a second column.
Details and common errors
Axes belong to each element. writing-mode and direction are inherited properties, so most descendants share the same axes as their parent. If you set a different writing-mode on a child, the child and its descendants use their own axes. Logical properties on that element resolve against its own writing mode. A vertical label inside a horizontal page therefore needs no special handling for its own padding or size.
direction does not rotate anything. Setting direction: rtl on a horizontal element reverses inline-start and inline-end. It does not touch the block axis. Do not expect it to flip vertical stacking.
dir in HTML is the safer way to set direction. The dir attribute carries meaning for the document, and browsers apply the matching direction through default styles. The CSS specification advises authors to use markup for direction, because it survives when styles fail to load. writing-mode, by contrast, is a presentational choice and belongs in CSS.
Physical properties do not follow. width, margin-left and top keep their physical meaning in every mode. A stylesheet that mixes them with logical properties can contradict itself in vertical text, for example by sizing the inline axis with width while spacing it with padding-inline.
Auto sizing can surprise you. A vertical-mode box inside a horizontal parent is an orthogonal flow. Its available inline space is not simply the parent's width. If an auto-sized vertical box collapses or stretches oddly, set an explicit inline-size or max-inline-size before debugging anything else.
What this enables
Once you can name the axes, the logical properties become a vocabulary instead of a list to memorize. inline-size and block-size set the extents. Properties with -inline-start, -inline-end, -block-start and -block-end in their names address the four edges. The shorthands -inline and -block address both ends of one axis at once. The following chapters apply this vocabulary to margins, padding, borders and positioning.
Exercise
An element has writing-mode: vertical-lr; direction: rtl; inline-size: 15rem; block-size: 6rem;. Which physical axis is the inline axis, how tall and wide is the box, and which physical edges are inline-start and block-start?
Show answer
The inline axis is vertical, because the mode is vertical. So inline-size: 15rem makes the box 15rem tall, and block-size: 6rem makes it 6rem wide. With direction: rtl in a vertical mode, the inline axis runs bottom to top, so inline-start is the bottom edge. In vertical-lr, blocks stack from left to right, so block-start is the left edge.
Exercise
A page sets writing-mode: vertical-rl on an article and width: 30rem on a paragraph inside it. Why is this likely a mistake for a text column, and which property should you use instead?
Show answer
In vertical-rl, the width is the block-axis extent, not the line length. The paragraph's lines are vertical, so width: 30rem limits how many columns of text can stack horizontally, not how long each line is. To control line length, set inline-size (or max-inline-size), which follows the inline axis in any writing mode.