The smallest and largest size, for padding, margin or font size.
The screen widths where the value starts and stops growing.
The clamped value will be between 1rem and 8rem, applied linearly between viewports of 24rem and 120rem.
CSS clamp() generator
One clamp() value replaces a stack of breakpoints. Pick a minimum and a maximum size, and every screen width in between gets its own value.
Drag the screen width and watch the value change in a real, scaled browser window. What you see is exactly what the CSS does.
Switch between text and container mode to tune fluid typography, padding, margin and gaps with the same formula.
Values are written in rem with a rem intercept, so they keep respecting browser zoom and the user’s font size setting.
The result, ready to paste:
font-size: clamp(1rem, 0.625rem + 1.563vw, 2.5rem);16px on a 384px screen, 40px on a 1920px screen, and a smooth line in between.
A CSS clamp() generator calculates a clamp() value that grows smoothly from a minimum size on small screens to a maximum size on large screens. You enter the two sizes and the viewport range, and it returns a value like clamp(1rem, 0.5rem + 2vw, 3rem) that you can paste into any CSS property that takes a length.
Divide the size range by the viewport range to get the slope, then subtract slope × minimum viewport from the minimum size to get the intercept. The preferred value is intercept + slope × 100vw. For 1rem to 8rem between 24rem and 120rem that gives clamp(1rem, -0.75rem + 7.292vw, 8rem). The generator does this for you.
Use rem for the minimum, the maximum and the intercept. rem values follow the user’s browser font size and zoom, while px values do not. You can still think in pixels: 16px is 1rem at the default font size, and the generator converts between the two.
Media queries switch a value at fixed breakpoints, so it jumps from one size to the next. clamp() changes the value continuously with the screen width, so every width gets its own size. Use clamp() for sizes and spacing, and media or container queries when the layout itself changes, like going from one column to three.
Yes. clamp() works in any property that accepts a length, including padding, margin, gap, width, height, border-radius and line-height. Switch the generator to container mode to preview spacing instead of text.
Yes. clamp() is supported in every current browser, including Chrome, Edge, Firefox and Safari, and has been since 2020.
Yes. Use an arbitrary value like text-[clamp(1rem,0.5rem+2vw,3rem)] for a one-off, or add the value to your theme. In Tailwind CSS v4 a --text-* or --spacing-* variable in @theme creates the utilities for you. See the Tailwind CSS clamp() guide for details.
It can be. Avoid font sizes in pure viewport units, because they shrink when users zoom in. Use rem for the bounds and the intercept, keep the maximum within about 2.5 times the minimum for text, and test at 200% zoom.
Use the smallest and largest widths your design is made for. A common range is 360px to 1440px, or 24rem to 120rem if you want the value to keep growing on large monitors. Outside that range the value stays at the minimum or maximum.