Skip to content
Tutorials Center
My learning

Topics

Lesson 43 of 139 ยท Text and Fonts

Line Height and Vertical Rhythm

Set comfortable line-height with unitless values, limit line length with the ch unit, and space paragraphs and headings for a calm, readable vertical rhythm.

Choosing a good font is only half of readable typography. The other half is space: the space between lines, the length of each line and the gaps between paragraphs and headings. Get these right and even a plain system font feels polished. Get them wrong and the most beautiful typeface turns into a tiring wall of text.

This lesson covers line-height and why it should almost always be unitless, how to limit line length with the ch unit, and how to space blocks of text so a page has a steady vertical rhythm.

What line-height controls

Every line of text sits inside an invisible line box. line-height sets the height of that box. The extra space beyond the font's own size is split evenly above and below the text, a little like padding on each line.

CSS
p {
  font-size: 1rem;      /* 16px */
  line-height: 1.5;     /* each line box is 24px tall */
}

The default value, normal, is decided by the font itself and is usually somewhere around 1.1 to 1.3. That is fine for single-line labels but too tight for paragraphs. For body text, values between 1.4 and 1.7 read comfortably; headings, which are bigger and shorter, look better around 1.1 to 1.3.

Comparing line heights

Always prefer unitless values

line-height accepts a plain number, a length (24px, 1.5rem), a percentage (150%) or em (1.5em). They look similar but inherit very differently:

  • A unitless number is inherited as the number. Every descendant multiplies it by its own font size.
  • A length, percentage or em is calculated once, on the element where you set it, and the resulting fixed pixel value is inherited.

That difference causes a classic bug: set line-height: 1.5em on body, and a large heading inside inherits 24px line boxes for 40px text. The heading's lines overlap.

Unitless vs em

The console shows 24px for the first heading and 60px for the second. That is why the rule of thumb is simple: write line-height without units.

A good base. Put line-height: 1.5 (or a similar number) on body, then tighten it on headings: h1, h2, h3 { line-height: 1.2; }. Many teams also include it in the font shorthand: font: 1rem/1.5 system-ui, sans-serif;.

Line height and single-line UI

line-height also affects buttons, badges and navigation links, since they contain a line of text. A large inherited value from body can make a button taller than you expect. Setting line-height: 1.2 (or similar) on compact components gives you predictable heights, and you control the rest with padding.

Readable line length (measure)

Typographers call the length of a line the measure. Lines that are too long make your eye lose its place when it jumps back to the start of the next line. Lines that are too short break the text into choppy fragments. A comfortable range for body text is roughly 45 to 75 characters per line.

The ch unit is perfect for this. One ch is the width of the "0" character in the current font, so 65ch is about 65 characters wide, whatever the font size.

CSS
.prose {
  max-width: 65ch;
}

Use max-width, not width, so the text still shrinks on narrow screens. Width and Height explains the difference.

Line length

The preview pane is narrow, so try widening the browser window or changing 45ch to 20ch and 90ch to feel the extremes.

Longer lines need more line height. The farther your eye travels, the more help it needs to find the next line. If your design forces a long measure, increase line-height slightly; for short lines in narrow columns, you can reduce it.

Spacing between paragraphs and headings

Browsers give paragraphs a default margin of 1em above and below; because vertical margins collapse, adjacent paragraphs end up 1em apart, not 2em. Headings get their own default margins, which vary by level.

Those defaults are a starting point. A few principles make text easier to scan:

  • Proximity shows relationships. A heading belongs to the text after it, so give it more space above than below. If a heading floats exactly halfway between two paragraphs, readers can't tell which one it introduces.
  • Use one direction for margins. Adding space only above elements (margin-block-start) makes spacing predictable, because each element is responsible for its own gap to the previous one.
  • Relate spacing to the text size. Spacing in em or rem, especially values tied to your line height (such as 1.5em for a 1.5 line height), keeps everything on a steady rhythm.

The flow pattern

A popular pattern removes all default margins inside an article and adds space between siblings only, using the next-sibling combinator:

CSS
.flow > * {
  margin-block: 0;
}
.flow > * + * {
  margin-block-start: var(--flow-space, 1em);
}

Every child except the first gets space above it. Nothing gets space at the very top or bottom, so the article sits neatly in whatever container holds it. You can raise --flow-space for headings to separate sections.

A steady vertical rhythm

Notice how each heading sits close to its own paragraph and far from the previous section. Change --flow-space values to see how much the grouping affects scanning.

A complete reading style

Here is a compact, production-ready set of reading styles that combines everything from this lesson:

CSS
body {
  font: 1.0625rem/1.6 system-ui, sans-serif;
}

h1, h2, h3 {
  line-height: 1.2;
  text-wrap: balance;     /* nicer heading line breaks */
}

.prose {
  max-width: 65ch;
}
.prose > * + * {
  margin-block-start: 1em;
}
.prose > :is(h2, h3) {
  margin-block-start: 2em;
}
.prose > :is(h2, h3) + * {
  margin-block-start: 0.5em;
}

text-wrap: balance evens out the lines of a multi-line heading; you will meet it in Wrapping, Overflow and Hyphens. For text that grows with the screen size, combine these ideas with Fluid Typography.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which line-height is generally best for long paragraphs of body text?

    Body text reads comfortably with roughly 1.4 to 1.7. Smaller values crowd the lines; much larger ones break the paragraph apart.
  2. 2. You set line-height: 1.5em on body (16px text). What line height does a 40px heading inside inherit?

    A value with units is computed once (1.5 ร— 16px = 24px) and that fixed length is inherited, so the big heading's lines overlap. A unitless 1.5 would give 60px.
  3. 3. What does max-width: 65ch do to a paragraph?

    ch is the width of the 0 character, so 65ch is roughly 65 characters. Using max-width lets the paragraph shrink on small screens.
  4. 4. How should a heading be spaced relative to the paragraphs around it?

    Proximity signals relationship. A heading belongs to the following content, so it should sit closer to it.
  5. 5. What does the selector in .flow > * + * { margin-block-start: 1em; } match?

    * + * matches an element that directly follows a sibling, so every child except the first gets space above it.

Summary

  • line-height sets the height of each line box; around 1.5 suits body text and 1.1โ€“1.3 suits headings.
  • Use unitless line-height values so each element multiplies by its own font size.
  • Limit line length to roughly 45โ€“75 characters with max-width in ch.
  • Longer lines need a little more line height; shorter lines can use less.
  • Give headings more space above than below, and space siblings in one direction.
  • The flow pattern (> * + *) adds consistent space between elements without stray outer margins.

Next: Wrapping, Overflow and Hyphens, where you control how text breaks across lines.