Skip to main content

Fluid type — CSS clamp()

Build a clamp(min, preferred, max) for responsive font-size (or any length) with vw and optional rem offset.

Set minimum and maximum with rem or px, add a vw fluid middle, optionally add rem to the middle (e.g. 0.5rem + 4vw). Copy one line of CSS and preview size in the sample box.

Middle value is vw plus optional rem. Example: clamp(1rem, 0.5rem + 3vw, 3rem) → set mid rem 0.5 and vw 3.

CSS

clamp(1rem, 4vw, 3rem)
Preview text at this clamp()

Quick guide

clamp() needs a real preferred value that sits between min and max at typical viewports — tune vw and mid rem in DevTools.

You can paste the same pattern for spacing (padding, gap) with different numbers.

The preview box uses your clamp as font-size so you can resize the window to feel the curve.

FAQ

Why is my text stuck at min or max?
The vw slope may be too shallow or steep; adjust vw and mid rem so the middle term crosses between min and max in your target viewport range.
px vs rem?
rem respects user font settings; px is fixed. Prefer rem for body text accessibility.
Safari?
clamp() is supported in current Safari; always test your real CSS in target browsers.
Uploaded?
No — this page only formats numbers into a CSS string.