Sub topic 13
Vertical rhythm and paragraph spacing
This chapter assumes you know how to set line-height and max-width in CSS, and that you understand leading as the space between lines of text. Here you will use the line height as a unit to space paragraphs.
What vertical rhythm means
Vertical rhythm is a consistent pattern of vertical spacing down a page. In body text, the usual way to get it is to make the space between paragraphs equal to one line of text. The eye then sees an even beat from line to line, and from paragraph to paragraph.
Derive the spacing from the line height
The line height is the unit. If font-size is 1rem and line-height is 1.5, each line is 1.5rem tall. A paragraph gap of 1.5rem is exactly one blank line.
p {
font-size: 1rem;
line-height: 1.5;
margin-block: 0 1.5rem;
}margin-block: 0 1.5rem sets the top margin to 0 and the bottom margin to 1.5rem. Each paragraph owns the space below it. This avoids a gap above the first paragraph in a container and keeps the rule simple.
Why a gap beats an indent in web text
Printed books often mark a new paragraph with an indent and no gap. On the web, a gap equal to one line is more common. It is easy to scan, and it needs no special first-paragraph rule. Use one method, not both. A gap and an indent together signal the break twice.
Keep the gap tied to the leading
If you change the leading, change the gap with it. The two must stay in step, or the rhythm breaks. A custom property makes this a single edit.
:root {
--line: 1.5rem;
}
p {
font-size: 1rem;
line-height: var(--line);
margin-block: 0 var(--line);
}Here line-height uses a length, not a unitless number. This keeps the arithmetic exact, but the line height no longer scales with an element's own font size. Use this form only for body text at a known size. For elements with other sizes, such as headings, set a unitless value or a multiple of --line.
Common errors
- Gap too small. Paragraphs run together and the text looks like one block. Tighter than the line height is rarely enough.
- Gap too large. Paragraphs look like separate items, and the reader loses the thread of the argument. More than about two lines is usually too much.
- Margins that collapse. Adjacent vertical margins in normal flow merge into the larger of the two. If paragraphs have both a top and a bottom margin, you get one gap, not two. Setting only the bottom margin avoids confusion.
- Gap and leading set separately. A designer changes
line-heightto1.6and forgets the margin. The gap is now slightly less than a line and the rhythm drifts.
How the pieces fit
Check it by eye
Squint at the page, or view it at a small size. The paragraphs should read as even bands separated by gaps of the same size. If one gap looks wider or narrower than the others, find the element that sets its own margin.
Exercise
A page sets p { font-size: 1.125rem; line-height: 1.5; }. What bottom margin gives a paragraph gap equal to exactly one line, and why?
Show answer
The line height is 1.125rem × 1.5 = 1.6875rem, so a bottom margin of 1.6875rem gives a gap of one line. Because the margin is derived from the line height, it must be updated whenever the font size or line-height ratio changes. A custom property such as --line: 1.6875rem keeps the two in step.
Exercise
Paragraphs have margin: 1.5rem 0. The designer expects 3rem between paragraphs. What gap appears, and what is the fix to keep it simple?
Show answer
The gap is 1.5rem, because adjacent vertical margins collapse to the larger one instead of adding. To keep it simple, set only a bottom margin, for example margin-block: 0 1.5rem.