CSS clamp() Fluid Value Generator
Enter a minimum and maximum size and two viewport widths to get a clamp() value that grows smoothly between them, in rem with a vw slope.
Use the tool
Why this tool exists
Fluid type and spacing remove the need for a pile of breakpoints: a heading can be 16px on a phone, 32px on a desktop and anything sensible in between. The formula for the middle value, a rem offset plus a vw slope, is easy to get wrong when worked out on paper.
Give this tool the two sizes and the two viewport widths where they apply, and it works out the slope and the intercept, converts to rem against your root size, and writes the complete clamp(). The minimum and maximum are swapped if you enter them the other way round, so a shrinking value also works. Test on real devices, and note that pure vw scaling ignores the user's zoom unless you keep the rem part, which this output does.
How to use it
- Enter the minimum and maximum size in pixels.
- Enter the viewport widths at which those sizes apply, and the root font size.
- Copy the clamp() value, or the ready font-size declaration.
Frequently asked questions
Why is there a rem term as well as vw?
A value in vw alone ignores the user font size setting. Adding a rem offset keeps zoom and text size preferences working, which helps accessibility.
What happens outside the two viewport widths?
The size stays at the minimum below the lower width and at the maximum above the upper width, because clamp() caps the middle value on both sides.
Can I use it for margins and padding?
Yes. The result is a plain length, so it works for any property that accepts one, such as padding, gap or width.
Does it work for shrinking values?
Yes. If the maximum size is smaller than the minimum, the slope is negative and the bounds are swapped into the right order inside clamp().