RevealTheme logo

CSS Clamp() Generator

Generate a fluid CSS clamp() value from a minimum and maximum size and the viewport range they map to. The tool computes the linear preferred value (a px offset plus a vw term) so a font size scales smoothly between breakpoints.

font-size: clamp(16px, 13.0909px + 0.9091vw, 24px);

How to use this tool

  1. 1

    Enter the minimum size in pixels (the value at and below your small viewport).

  2. 2

    Enter the maximum size in pixels (the value at and above your large viewport).

  3. 3

    Set the min and max viewport widths in pixels that define where scaling starts and stops.

  4. 4

    Read the generated clamp() declaration and click Copy to paste it into your stylesheet.

What is a CSS clamp() value and how does this generator build one?

CSS clamp(MIN, PREFERRED, MAX) returns the PREFERRED value but never lets it drop below MIN or rise above MAX. For fluid typography the trick is the middle argument: it must be a viewport-relative expression that, when evaluated, passes through MIN at your small viewport and MAX at your large one. This tool computes that expression with linear interpolation. It finds the slope between your two size/viewport points, slope = (maxSize - minSize) / (maxVw - minVw), converts it to a vw coefficient by multiplying by 100, and derives the px intercept where the line would cross a zero-width viewport. The output looks like clamp(16px, 11.4286px + 0.7143vw, 24px). Below the min viewport clamp() pins to 16px; above the max it pins to 24px; in between the value rises in a straight line. Because clamp() and vw are resolved by the browser, the size updates continuously as the window resizes, with no media queries. Note this generator emits px and vw units (not rem), assumes a single linear segment, and does not re-order arguments, so you must enter a max that is larger than the min and a max viewport larger than the min viewport for sensible output.

Common use cases

  • Building fluid headings that grow from 24px on mobile to 48px on desktop without writing media-query breakpoints.

  • Setting responsive body copy that stays readable between a 320px phone and a 1200px laptop.

  • Scaling section padding or gap values fluidly so layouts breathe proportionally across screen sizes.

  • Replacing a stack of font-size overrides at 480px, 768px, and 1024px with one clamp() declaration.

  • Generating clamp() values for a design system so spacing and type scale consistently from one formula.

  • Quickly checking the px and vw math for a fluid value you sketched out in a design tool like Figma.

Frequently asked questions

Does clamp() work in all browsers?
Yes. clamp() has been supported in Chrome, Firefox, Safari, and Edge since around April 2020, so it is safe in production for any modern evergreen browser. Very old browsers (such as IE11) do not support it, so provide a static fallback font-size before the clamp() line if you must support them.
Why does the output use px and vw instead of rem?
This generator computes the preferred value with px for the offset and vw for the viewport term, matching the numbers you type in. It does not convert to rem. If you prefer rem for accessibility (so the size respects the user's root font setting), divide the px values by your root font size, typically 16, and substitute the rem units by hand.
What happens outside the viewport range I set?
Outside the range the value is flat. Below the min viewport width clamp() returns the min size, and above the max viewport width it returns the max size. Scaling only happens linearly between the two viewport widths you provide.
What if I enter a max smaller than the min?
The tool does not validate or swap your inputs. clamp() expects min, preferred, max in ascending order, so an inverted range produces a slope and a declaration that will not behave as intended. Always set the max size larger than the min size and the max viewport larger than the min viewport.
Why is there a long decimal in the result?
The intercept and slope are computed to four decimal places to keep the line passing exactly through your two points. You can round the px and vw numbers for cleaner CSS; small rounding shifts the curve by a fraction of a pixel and is usually invisible.
Can I use this for spacing, not just font size?
Yes. The math is unit-agnostic. Although the output is shown as a font-size declaration, you can copy the clamp(...) expression and apply it to padding, margin, gap, width, or any length property that accepts a fluid value.
Is my data sent anywhere?
No. All calculation runs locally in your browser with JavaScript. Your numbers are never uploaded to a server, and the Copy button writes the result to your clipboard on your own device.

Related tools