Vertical Rhythm and Spacing
What you'll learn: How to create harmonious, consistent vertical spacing throughout your typography by basing all spacing values on your line-height.
Vertical rhythm is the practice of maintaining consistent, predictable spacing between text elements using a baseline grid. Just like music has a steady beat that guides the rhythm, your webpage can have a consistent vertical "beat" that guides the eye smoothly down the page.
The Core Principle
The idea is simple: choose a base line-height (the space between lines of text), then make all your vertical margins and padding multiples of that base unit. If your body text has a line-height of 1.5 and a font-size of 16px, your baseline unit becomes 24px (16 × 1.5). Every vertical space—heading margins, paragraph spacing, section padding—should then be 24px, 48px, 72px, or other multiples.
Why It Matters
Without vertical rhythm, spacing feels arbitrary and chaotic. Some gaps are too tight, others too loose, with no clear pattern. With vertical rhythm, everything aligns to an invisible grid, creating a calm, organized reading experience. Your text "breathes" naturally because the spacing relationships are mathematically related.
Practical Implementation
Using CSS custom properties makes this manageable:
:root {
--font-size-base: 1rem; /* 16px */
--line-height-base: 1.5;
--rhythm-unit: calc(var(--font-size-base) * var(--line-height-base)); /* 24px */
}
p {
margin-bottom: var(--rhythm-unit); /* 24px */
}
h2 {
margin-top: calc(var(--rhythm-unit) * 2); /* 48px */
margin-bottom: var(--rhythm-unit); /* 24px */
}
Now every element maintains the rhythm, and changing your base values updates everything proportionally.
Key Takeaway: Vertical rhythm creates visual harmony by spacing all text elements in consistent multiples of your base line-height, making content feel organized and easy to read.