CSS clamp() Generator | Fluid Typography Without Media Queries
Enter a min and max viewport width plus a min and max value, and this tool solves the linear interpolation for you and returns a ready-to-paste clamp(min, slopevw + intercept, max) declaration. It covers font-size, padding, gap, border-radius and more, toggles between px and rem, and shows both the slope/intercept math and a per-viewport preview of the resulting value.
💡 About this tool
If you have ever hand-tuned a stack of media queries just to make a heading grow from 24px on mobile to 48px on desktop, you know the pain: the text jumps in steps, and every new breakpoint means another rule. clamp() replaces that whole ladder with one line that scales smoothly across the entire range.
The catch is the middle argument. clamp() takes a minimum, a preferred value, and a maximum, and you want the preferred value to track the viewport — something like 2vw + 8px. Working out that slope and intercept by hand means solving a linear equation every time: the slope is (maxValue − minValue) / (maxVW − minVW) and the intercept is minValue − slope × minVW. Doable, but tedious and error-prone when you are iterating on a design.
Drop your four numbers in and the calculator does the algebra and hands back the declaration. The breakdown panel shows exactly how the slope and intercept were derived, so the output is not a black box — you can sanity-check it or tweak the inputs with confidence. The preview chart renders the actual computed value at common widths from 320px to 1920px, including where it clamps flat at each end.
🧐 Frequently Asked Questions
Can I type px values but output rem? Yes. Switch the output unit to rem and the tool converts from px using your root font-size (16px by default). For font-size specifically, rem output is generally preferred because it respects the user's browser font-size setting.
What happens if the max value is smaller than the min value? You get a negative slope, so the property shrinks as the viewport grows. That is perfectly valid CSS and handy for things like spacing you want to tighten on larger screens.
Can the min and max viewport be the same? No. With equal or inverted viewports (min ≥ max) the slope of the line is undefined, so the tool shows an error and stops calculating. Keep min < max.
Is a vw-based clamp() an accessibility problem?
A preferred value made of vw alone can resist user zoom. This tool keeps a fixed vw + rem (or px) offset, so when your minimum is rem-based you retain some zoom resilience instead of pinning everything to viewport units.
Does it work for properties other than font-size? Yes. You can pick padding, margin, gap, width, height, border-radius, letter-spacing or line-height from the presets, or enter any custom property name.
📚 Fun Facts
clamp() is a math function standardized in the CSS Values and Units Module Level 4, alongside min() and max(). Under the hood clamp(MIN, VAL, MAX) is equivalent to max(MIN, min(VAL, MAX)) — it returns the middle of the three values, which is a useful mental model when a result looks surprising. Browser support landed across the major engines around 2020, and fluid typography quickly became the default way to handle responsive type. The trick of adding a vw term to a fixed unit predates the function — it circulated for years under names like "fluid type" and "CSS locks" — but it used to require calc() plus a couple of media queries. Collapsing all of that into a single clamp() is what made the pattern mainstream.