Text that looks right on a phone often looks tiny on a big monitor, and the other way round. The old fix was a stack of media queries, with sizes that jump at each breakpoint. clamp() lets the size grow smoothly instead, in a single line of CSS. The maths behind the middle value is fiddly, which is exactly what this calculator handles.
A worked example
Say your headings should be 18px on a 360px phone and 40px on a 1280px laptop. The size needs to grow by 22px across 920px of width, which is about 2.39px for every 100px. The calculator turns that into:
font-size: clamp(1.125rem, 0.587rem + 2.3913vw, 2.5rem);
Below 360px the heading stays at 18px; above 1280px it stops at 40px; in between it scales evenly. On a 768px tablet it comes out at about 27.8px, as the table shows.
Choosing the numbers
- Widths: 360–1280px covers most phones up to standard laptops. Use 1440px or more if your layout gets wider.
- Body text: keep the range small, for example 16 to 18px. Big swings in paragraph size feel odd.
- Headings: a larger range, such as 28 to 56px, gives a strong hierarchy on desktop without overflowing on phones.
Building a type scale
Make one clamp() for each heading level and store them as custom properties, such as --step-1 to --step-5. Choose the custom property option and the calculator writes the variable for you.
How to use the CSS Clamp Calculator
- Enter the smallest and largest size in pixels, for example 18 and 40.
- Enter the screen widths where scaling should start and stop, for example 360 and 1280.
- Choose rem (recommended) or px output, and the property to write.
- Drag Try a screen width to preview the size at any width, or check the table.
- Click Copy CSS.
Features
- Exact linear interpolation: the value hits your minimum and maximum at the chosen widths.
- rem output with a configurable root font size, so text respects user zoom settings.
- Live preview slider and a table of sizes at eight common device widths.
- Writes font-size, padding, margin, gap, width or a custom property.
- Warning when the range is so wide that it may block 200% text zoom (WCAG 1.4.4).
Frequently asked questions
How does clamp() work?
clamp(min, preferred, max) uses the preferred value, but never goes below min or above max. For fluid type, the preferred value mixes rem and vw, so the size grows with the screen width between your two limits.
Why use rem instead of px in clamp()?
rem values grow when a user raises their browser’s default font size. A clamp() built only from px and vw ignores that setting, which is an accessibility problem. The calculator uses rem for the limits and the fixed part.
Is fluid typography accessible?
It can be. The risk is that vw units don’t grow when people zoom, because zooming makes the viewport narrower. Keep the largest size under about 2.5 times the smallest, and test with browser zoom at 200%.
Can I use clamp() for spacing too?
Yes. clamp() works for any length, such as padding, margins, gaps and widths. Fluid spacing keeps layouts balanced between phones and large monitors without extra media queries.
Written by Dewan Razib