The Same Technique, Different Properties
clamp() works with any CSS property that accepts a length value — it's not limited to font-size. The same three-value structure and the same underlying formula apply equally well to spacing, sizing, and several other properties.
Fluid Padding and Margin
.card {
padding: clamp(1rem, 3vw + 0.5rem, 2.5rem);
}
Rather than a fixed padding value that feels cramped on large screens or excessive on small ones, this scales the spacing proportionally alongside the viewport — tight on mobile, roomier on desktop.
Fluid Width
.container {
width: clamp(300px, 90%, 800px);
}
Here, the preferred value is a simple percentage rather than a calculated vw+rem formula — a reminder that the preferred value doesn't always need the full linear interpolation formula; sometimes a straightforward percentage is exactly the right middle value.
Readable Line Length With ch Units
.article-text {
width: clamp(45ch, 70%, 75ch);
}
The ch unit represents the width of the "0" character in the current font — commonly used to constrain line length for readability, since text that's too wide per line is measurably harder to read. Wrapping this in clamp() keeps line length within a comfortable range regardless of container width.
Why This Consistency Is Useful
Once you understand the clamp() pattern for one property, it transfers directly to any other length-based property — the mental model, the three-value structure, and the underlying math all stay the same, only the specific min/max/preferred values change based on what you're sizing.
Ready to calculate clamp values for spacing or sizing?
Open Clamp Generator