Sub topic 3
The block and inline axes
This chapter assumes you know the box model, the width, height and position properties, and the lang and dir HTML attributes. It builds on the previous chapter on writing mode and direction.
Two axes instead of two dimensions
Physical CSS talks about horizontal and vertical. Logical CSS talks about the inline axis and the block axis. These axes are the base for every logical property in later chapters.
- The inline axis is the direction in which text runs within a line.
- The block axis is the direction in which lines, paragraphs and other block boxes stack.
The two axes are always perpendicular. Which physical direction each one points to depends on two properties:
writing-modesets the block axis, and also whether the inline axis is horizontal or vertical.direction(or thedirattribute) sets which way the inline axis points along its line.
The mapping
| 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-lr | ltr | top to bottom | left to right |
English and Arabic both use horizontal-tb, so their block axes match. Only the inline direction flips. Traditional Japanese uses vertical-rl: lines run top to bottom, and each new line is added to the left of the previous one.
Sizes follow the axes
inline-size is the size along the inline axis. block-size is the size along the block axis. In horizontal text they equal width and 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 this box is 20rem tall and 10rem wide. The same rule in horizontal-tb would give a box 20rem wide and 10rem tall. You don't change the CSS to get this. The writing mode does it.
Common errors
- Treating
inline-sizeas a synonym forwidth. It is only the same value in horizontal writing modes. - Mixing physical and logical sizes on one element. If you set
width: 20remandblock-size: 10remon the vertical box above, both set the same physical dimension, and the later declaration wins. - Expecting
direction: rtlto change the block axis. It only reverses the inline direction. The block axis stays the same unlesswriting-modechanges. - Setting
directionin CSS for document-level text. Prefer thedirattribute in HTML. It carries meaning that CSS alone does not, and it is respected when styles fail to load.
Exercise
An element has writing-mode: vertical-lr and direction: ltr. Which physical direction does the block axis run in, and which physical dimension does inline-size set?
Show answer
The block axis runs left to right, because new lines are added to the right of earlier ones. The inline axis is vertical, so inline-size sets the element's physical height.