Fluid Line Height and Spacing
You'll learn how to make your line-height, margins, and padding scale smoothly across screen sizes, keeping your text readable and your layout balanced.
Just as you've scaled font sizes fluidly with clamp() and viewport units, your vertical spacing should also adapt proportionally. Fixed line-heights and spacing look cramped on mobile or overly loose on large screens. Fluid spacing maintains visual harmony as your typography scales.
Why Fluid Spacing Matters
Think of line-height and spacing like the cushioning around furniture. Too little on a small couch feels tight; too much on a large couch looks absurd. Your text needs breathing room that adjusts with its size.
Applying Fluid Line Height
Line-height often works best as a unitless ratio (like 1.5), which automatically scales with font size. But you can also make it fluid:
body {
font-size: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
line-height: clamp(1.4, 1.3 + 0.2vw, 1.6);
}
This keeps tighter line spacing on mobile (1.4) and more generous spacing on desktop (1.6).
Fluid Margins and Padding
Apply the same technique to margins and padding:
section {
padding: clamp(1rem, 0.5rem + 2vw, 3rem);
margin-bottom: clamp(1.5rem, 1rem + 2vw, 4rem);
}
h2 {
margin-top: clamp(1.5rem, 1rem + 1.5vw, 3rem);
}
Your spacing grows proportionally, maintaining vertical rhythm (consistent visual flow) at every screen size.
Key Takeaway: Use clamp() and viewport units on line-height, margins, and padding to create proportional vertical spacing that adapts seamlessly across all devices, keeping your layouts balanced and readable.