Create responsive clamp() values for fluid typography and spacing.
How it works
The CSS clamp(min, preferred, max) function picks a value between a minimum and a maximum based on a preferred expression. For fluid scaling, the preferred value is a calc() that linearly interpolates between two sizes across a viewport range: minSize + (maxSize - minSize) * ((100vw - minVw) / (maxVw - minVw)). The browser clamps the result so the property never goes below the minimum or above the maximum, giving smooth, responsive typography and spacing without media queries.
Frequently asked questions
How does CSS clamp() work?
CSS clamp(min, preferred, max) sets a value that scales between a minimum and maximum based on a preferred (usually viewport-relative) calculation. The browser picks the minimum if the preferred is smaller, the maximum if it's larger, otherwise the preferred value.
What is the clamp() formula for fluid typography?
The formula is clamp(minSize, minSize + (maxSize - minSize) * ((100vw - minViewport) / (maxViewport - minViewport)), maxSize). It linearly scales the font size between two viewport widths.
What units can I use with clamp()?
You can use any valid CSS length units: px, rem, em, vw, vh, %, or calc() expressions. For fluid typography, rem combined with vw is the most common pattern to respect user font-size preferences.