liveBook · Manning

Line height

As explained in Math for Web Design

The CSS line-height property specifies the height of a line box or the spacing allocated to each line of text.

If paragraph lines feel cramped, check line-height alongside font-size and line length. A unitless line-height multiplies the element’s font size: at 20px, a value of 1.4 gives 28px of line height. For body text, a practical starting point is around 1.4–1.5. section 8.1 section 8.1.1

Inheritance can change the result. A parent with font-size: 20px and line-height: 150% computes a 30px line height; a child with font-size: 16px inherits that 30px value. Change the parent to line-height: 1.5, and the child inherits the multiplier instead, computing its own line height as 16 × 1.5 = 24px. Use a unitless value when descendants should retain the same proportion. section 3.4.6 section 3.1.3

.parent {
    font-size: 20px;
    line-height: 1.5;    #1
}
.child {
    font-size: 16px;
}

Compare the unitless parent declaration with the child’s different font size; the inherited multiplier produces a 24px line height. section 3.4.6

Line-height also works with font-size and max-width to shape readable paragraphs. In one scaling scheme, start with a 16px font, a 1.45 line-height, and a 480px maximum width. For a chosen font size in pixels, calculate line-height as 1.45 − (font size − 16) / 100. A 24px font therefore gets 1.37; the paired maximum width is 720px. Keep CSS custom-property inputs unitless for the calculation, adding px where a length is needed. section 8.1.2

Table 8.1 Calculated line heights and maximum widths based on different font sizes

Font size

Calculated line height

Calculated maximum width

12px

1.49

360px

16px

1.45

480px

20px

1.41

600px

24px

1.37

720px

28px

1.33

840px

32px

1.29

960px

Check the paired font sizes, line heights, and maximum widths produced by that scaling scheme. section 8.1.2

Repair a cramped article

An article with 16px text, a 1.2 line-height, and unrestricted line length is difficult to read. Choosing 20px text, a 1.41 line-height, and a 600px maximum width addresses all three problems together. section 8.1.5

How Math for Web Design covers it

How deep it goes
Works through inheritance calculations and formulas that scale line-height with font size or width, then applies the values in CSS.
Examples
Compares percentage and unitless inheritance, tabulates scaled values, and repairs a cramped article.
What it assumes
Assumes basic CSS font-size declarations and arithmetic while defining the variables used in its scaling formulas.
What you can do after
Apply it via CSS line-height and custom properties to calculate spacing and coordinate it with font size and maximum width.
How it connects
Connects line-height to font-size, line length, CSS inheritance, custom properties, and calc().

Also explained in

Compare how 8 books explain line height →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Math for Web Design. The section links point to the parts of the book it draws on.