06
Spacing
Whitespace is not empty space. It groups ideas. A heading with the wrong margin belongs to the paragraph above, even when it shouldn't.
4 min read
A heading's meaning is partly determined by what sits closest to it. Not by font size. Not by semantic HTML. By proximity. The law of proximity, a core Gestalt principle, holds that elements near each other are perceived as related.
Compare
The paragraph above talks about billing cycles.
Security settings
This paragraph is about two factor auth, but the tight margin above makes the heading feel like it belongs to billing.
The paragraph above talks about billing cycles.
Security settings
Same words. The heading now clearly introduces this section, because space above separates it from what came before.
Margin is grouping. More space above a heading than below it ties the heading to the content that follows. Equal margins, or tighter above than below, leave the heading adrift between two unrelated blocks.
Spacing
The paragraph above talks about billing cycles.
Security settings
This paragraph is about two factor auth. The heading should introduce this thought, not the billing paragraph above it.
Drag the margin above the heading. At 0.25em, the heading visually merges with the paragraph above. Your eye reads them as one unit. At 1.5em and above, the heading claims the section below. You feel the grouping shift before you read a word.
The standard pattern: generous top margin, tight bottom margin. The heading looks forward, not backward.
Symmetric margins, 1.5rem both ways, create the same problem in reverse: the heading floats between blocks. It doesn't introduce security settings; it interrupts the billing copy above.
The Rule
Headings need more margin-top than margin-bottom, typically 2x the space above as below.
Proximity grouping is automatic and preattentive. Wrong spacing overrides semantic HTML. A <h2> with tight top margin still reads as a continuation of the previous section, regardless of its tag.
h2, h3 {
margin-top: 2em;
margin-bottom: 1em;
}
h2 + p,
h3 + p {
margin-top: 0;
}h2, h3 {
margin-top: 2em;
margin-bottom: 1em;
}
h2 + p,
h3 + p {
margin-top: 0;
}Common Mistake
Applying symmetric vertical margins to headings, margin: 1.5rem 0, which centers the heading between two blocks instead of anchoring it to the content below.