CSS clamp() fluid typography generator
Generate the CSS clamp() for a text size that grows fluidly between two viewport widths, with a preview, a type scale you can export as CSS variables and an accessibility check.
Your data stays on your computer. Files are processed in your browser and are never uploaded.
Parameters
You can write the unit in the value (16px, 1.25rem): the one chosen above only applies to numbers without a unit.
Result
font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);
- Slope
- 0.8333vw
- Intercept
- 13.3333px (0.8333rem)
- Smallest value
- 16px
- Largest value
- 24px
Preview
At a 640px viewport the size is 18.67px.
Fluid typography adapts to the width of the screen.
Fluid type scale
It starts from the minimum and maximum sizes above (step 0) and multiplies them by the ratio at each step.
| Variable | Min (px) | Max (px) | clamp() | Preview |
|---|---|---|---|---|
| --step--2 | 11.11 | 15.36 | clamp(0.6944rem, 0.6059rem + 0.4426vw, 0.96rem) | Aa |
| --step--1 | 13.33 | 19.2 | clamp(0.8333rem, 0.7111rem + 0.6111vw, 1.2rem) | Aa |
| --step-0 | 16 | 24 | clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem) | Aa |
| --step-1 | 19.2 | 30 | clamp(1.2rem, 0.975rem + 1.125vw, 1.875rem) | Aa |
| --step-2 | 23.04 | 37.5 | clamp(1.44rem, 1.1387rem + 1.5063vw, 2.3438rem) | Aa |
| --step-3 | 27.65 | 46.88 | clamp(1.728rem, 1.3274rem + 2.0028vw, 2.9297rem) | Aa |
| --step-4 | 33.18 | 58.59 | clamp(2.0736rem, 1.5441rem + 2.6475vw, 3.6621rem) | Aa |
| --step-5 | 39.81 | 73.24 | clamp(2.4883rem, 1.7919rem + 3.4822vw, 4.5776rem) | Aa |
:root {
--step--2: clamp(0.6944rem, 0.6059rem + 0.4426vw, 0.96rem);
--step--1: clamp(0.8333rem, 0.7111rem + 0.6111vw, 1.2rem);
--step-0: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);
--step-1: clamp(1.2rem, 0.975rem + 1.125vw, 1.875rem);
--step-2: clamp(1.44rem, 1.1387rem + 1.5063vw, 2.3438rem);
--step-3: clamp(1.728rem, 1.3274rem + 2.0028vw, 2.9297rem);
--step-4: clamp(2.0736rem, 1.5441rem + 2.6475vw, 3.6621rem);
--step-5: clamp(2.4883rem, 1.7919rem + 3.4822vw, 4.5776rem);
}
How it is computed
The slope is (max − min) / (maximum viewport − minimum viewport) and the intercept is min − slope × minimum viewport. The result is clamp(min, intercept + slope vw, max), with lengths in rem so they follow the font size the user chose.
Accessibility
Using rem in the intercept and the limits keeps text zoom working. If the maximum is more than 2.5 times the minimum, the upper limit may prevent reaching the 200% required by WCAG 1.4.4: the tool warns you.
Privacy
The calculation happens in your browser: the values are not sent to any server.
How to use it
- Enter the minimum and maximum text size (px or rem) and the viewport widths it should vary between.
- Copy the font-size declaration with the clamp() and try the effect with the simulated width slider.
- For a complete scale set the ratios and copy the CSS variables for steps -2 to 5.
Frequently asked questions
Why is the result in rem?
The rem follows the font size the user chose in the browser. If the limits were in pixels, someone who set a larger font would not see it change.
What does the WCAG 1.4.4 warning mean?
The criterion requires that text can be enlarged up to 200% without losing content. With browser zoom the viewport in CSS pixels shrinks, so the size drops toward the minimum: if the maximum is over 2.5 times the minimum, the room to enlarge may not be enough. This is a rule of thumb: also test with real zoom.
Which viewport values should I choose?
Usually 320 px (a small phone) for the minimum and between 1200 and 1440 px for the maximum. Outside that range the size stays at the limits.
How do I use the scale?
Paste the variables in :root and use them as font-size: var(--step-0) for body text, var(--step-3) for headings. Step 0 is the size you chose, negative steps are smaller.
Are the values sent to a server?
No: the calculation happens in your browser.