liveBook · Manning

Spacing

As explained in CSS in Depth, Second Edition

Design spacing is the arrangement of empty space between and around interface elements.

Design spacing arranges empty space between and around interface elements. Consistent measurements establish visual patterns, while deliberate changes in whitespace can create emphasis and hierarchy. section 11.1.1 section 11.1

Apply spacing by combining several practical concerns:

  • Start with margins when matching precise distances between elements, then adjust for relative units and line-height. section 12.1
  • Treat typography as part of spacing: line-height controls vertical distance between lines, while letter-spacing controls horizontal distance between characters. section 12.6
  • Use flexbox gap and alignment properties when spacing items inside a flex container, adding them after the main layout is established. section 4.4
  • Reuse consistent spacing patterns, then break them intentionally when an important element needs stronger contrast. section 11.1

Turning a measured mockup into a page

A design mockup may specify 10 px between navigation buttons, 40 px below a hero image, and 30 px between a column heading and its paragraph. Repeated values such as 10 px and 25 px create a coherent visual rhythm; implementation then preserves those relationships as the page gains content. section 11.1.1

Spacing text for comfortable reading

Compare compressed, comfortable, and overly spread text. Very tight spacing increases concentration and makes the page feel cramped; excessive spacing draws attention to individual letters. Adjusting line-height and letter-spacing can improve readability and engagement. section 12.6

Figure 11.4 A mockup of the page design with annotated measurements
figure

Use the annotated mockup to inspect how exact measurements connect individual elements into a repeated page-wide spacing pattern. section 11.1.1

How CSS in Depth, Second Edition covers it

How deep it goes
Explains measured layouts, margins, relative units, line-height, letter-spacing, and flexbox gap without detailing CSS implementations.
Examples
Uses annotated mockup measurements, navigation buttons, hero content, columns, and text samples with varied spacing.
What it assumes
Assumes a page with colors and rough layout, then teaches precise spacing adjustments from that starting point.
What you can do after
Apply spacing via CSS margins, relative units, line-height, letter-spacing, and flexbox gap while preserving visual patterns.
How it connects
Connects spacing with typography, line-height, letter-spacing, flexbox, contrast, whitespace, and modular CSS.

Also explained in

Compare how 2 books explain spacing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.