CSS Clamp Generator
Developer Tools · Added
A heading that reads well at 320px is usually too small at 1440px, and one sized for the desktop overflows the phone. Media queries solve that in steps; clamp() solves it as a smooth line between two points you choose. This builds that line — a minimum, a maximum and the rem-plus-vw expression that joins them — and shows what the result actually computes to at each common screen width, so you can check the curve rather than trusting it.
How to use the css clamp generator
- 1Set the size you want at the narrow end and the size you want at the wide end, both in pixels.
- 2Set the two viewport widths those sizes apply at. Outside that range the value holds at the nearer bound.
- 3Set the root font size if your CSS changes it from the browser default of 16px.
- 4Press Generate and copy the declaration.
- 5Check the table underneath, which shows the computed size at nine screen widths and marks where the value is being held at a bound rather than scaling.
Examples
Fluid body text
- Input
- 16px at 320px, 18px at 1280px
- Result
- clamp(1rem, 0.9167rem + 0.2083vw, 1.125rem)
A gentle slope. Body text rarely wants to move much — a couple of pixels across the whole range is usually plenty.
A page heading
- Input
- 28px at 320px, 56px at 1280px
- Result
- clamp(1.75rem, 1.1667rem + 2.9167vw, 3.5rem)
Headings carry fluid scaling far better than body copy, which is why they are what this technique is usually used for.
A value that shrinks as the screen grows
- Input
- 32px at 320px, 16px at 1280px
- Result
- The bounds are written in the order clamp() needs, and the tool says so
Left the intuitive way round, the browser silently pins the value and nothing scales at all.
About the css clamp generator
The line, and where the numbers come from
Two points define a line: the size you want at the narrow viewport and the size you want at the wide one. The slope is the difference in sizes divided by the difference in widths — how many pixels the value gains per pixel of screen. Multiply that by 100 and it is a vw figure, since 1vw is one hundredth of the viewport width.
The intercept is where that line would cross a viewport width of zero, which is a hypothetical screen but a perfectly real number. Expressed in rem it becomes the constant term of the preferred value. Adding the two gives a value that passes exactly through both of your chosen points and interpolates smoothly between them.
Outside the range, the bounds take over. Below the narrow viewport the value holds at the minimum; above the wide one it holds at the maximum. The table in the results marks which rows are scaling and which are held, which makes it easy to see whether the range you chose covers the screens you care about.
When a clamp is the wrong tool
Fluid scaling is continuous, and some design changes are not. If a heading needs to drop from three lines to one, or a layout needs to switch from stacked to side-by-side, that is a container query or a media query — no amount of smooth interpolation expresses a change in arrangement.
It is also worth resisting the temptation to make everything fluid. A page where every size scales independently loses its typographic relationships: the ratio between a heading and its body text drifts as the screen changes, and what looked balanced at one width looks wrong at another. A common approach is to make one value fluid and derive the rest from it with a fixed ratio, so the relationships hold while the overall scale moves.
Finally, watch the extremes. A steep slope that looks reasonable between 320px and 1280px can produce something absurd on a 3440px ultrawide if the maximum is set too high, and something unreadably small on a narrow phone if the minimum is too low. The samples table exists to make both ends visible before the CSS ships, and the tool warns when a floor falls below comfortable reading size.
Frequently asked questions
Why not just use vw on its own?
How does clamp() actually resolve?
Should I use px or rem for the bounds?
What viewport widths should I pick?
Can I use this for padding and margins too?
Related tools
CSS Unit Converter
Converters
Convert px, rem, em, pt, %, vw and vh against a root font size you set.
CSS Flexbox Generator
Developer Tools
Build a flex layout against a live preview and copy CSS containing only the properties you changed.
CSS Grid Generator
Developer Tools
Build a grid visually — tracks, gaps, alignment and cell spans — and copy the CSS it produces.