Sub topic 10
Spacing and proximity: tying headings to their text
This chapter assumes you know the basics of type (size, weight, leading) and can read simple CSS. It covers how space groups text, so readers can tell which heading belongs to which paragraph.
The proximity principle
Proximity means that items placed close together look related, and items placed far apart look separate. In a layout, space often does more grouping work than borders or color do.
A subhead has to attach to the text it introduces. If the gap above a subhead matches the gap below it, the subhead floats between two paragraphs. The reader cannot tell which one it opens.
The rule is simple: put more space above a heading than below it.
Setting the gaps in CSS
Use em units for heading margins. An em is relative to the element's own font size, so the gaps scale when the heading size changes.
h2 {
font-size: 1.563rem;
font-weight: 600;
margin-top: 2em;
margin-bottom: 0.5em;
}
h2 + p {
margin-top: 0;
}Here the heading has a top margin of 2em and a bottom margin of 0.5em, a 4:1 ratio. The selector h2 + p targets a paragraph that directly follows an h2. Setting its top margin to 0 stops the paragraph from adding extra space and weakening the bond.
Spacing relates to leading
Paragraph spacing and line height work together. Leading sets the space between lines inside one block. Margins set the space between blocks. For the grouping to be visible, the space between blocks must be clearly larger than the space between lines.
If paragraphs are separated by a gap about the size of one line, they read as separate units. Headings then need an even larger gap above them, so they read as section breaks.
| Relationship | Typical gap | Effect |
|---|---|---|
| Line to line (leading) | 1.4 to 1.6 times the font size | Reads as one paragraph |
| Paragraph to paragraph | About 1 line | Reads as separate paragraphs |
| Subhead to its paragraph | 0.5em | Reads as attached |
| Previous paragraph to subhead | 1.5em to 2em | Reads as a new section |
Headlines and the lead
A headline at the top of an article follows the same logic. Keep it close to the intro paragraph or byline that belongs to it, and leave more room between that group and the content around it. Large headlines with tight leading also gain from a small bottom margin, since a big gap makes a big heading look detached.
Common errors
- Equal margins. A heading with
margin: 1em 0sits midway between two paragraphs. Set the top and bottom values separately. - Stacked margins. In CSS, adjacent vertical margins collapse into the larger of the two. If a heading follows another heading, you may get less space than you expect. Check the result in the browser.
- Too much space everywhere. If every gap is large, none of them signals grouping. Keep a small set of spacing values and reuse them.
- Fixed pixel margins. Pixel gaps do not follow the heading size. When you change the type scale, the ratios break.
Check your work
Blur your eyes or squint at the page. The headings should visibly cluster with the text beneath them. If you see a heading that seems to belong to the paragraph above, increase its top margin or reduce its bottom margin.
Exercise
A subhead has margin-top: 1em; margin-bottom: 1em;. Readers say it seems to belong to the paragraph above it. What change fixes this, and why?
Show answer
Increase the top margin (for example to 2em) and reduce the bottom margin (for example to 0.5em). Proximity makes elements that are closer together look related. A smaller gap below ties the subhead to the paragraph it introduces, and a larger gap above separates it from the previous section.