Lab 06
CSS clamp() generator for fluid typographyFluid typewithout the maths.
Set the smallest and largest size, and the screen widths where the change starts and stops. You get a CSS clamp() in rem and vw that grows in a straight line between them, a chart of how it behaves, and a live preview at any width.
Start from
font-size: clamp(2.25rem, 1.3696rem + 3.913vw, 4.5rem);Grows 3.913px for every 100px of viewport between 360px and 1280px. Below and above that it stays at 36px and 72px, at a 16px root.
Preview
At 800px wide the value is 53.22px (3.326rem).
Fluid type that grows with the screen.
The real clamp() in this window. Resize the browser to watch it change.
Fluid type that grows with the screen.
A CSS clamp() generator for fluid typography
This CSS clamp() generator writes fluid sizes for you. Set the smallest and largest size, and the screen widths where the size should start and stop growing. You get one line of CSS that scales in a straight line between them, with a chart and a preview so you can see it before you ship it.
- 01
Enter the sizes
Set min size and max size in px, then min viewport and max viewport: the widths where the growth starts and stops. Or start from a preset such as Body text, H1 or Section spacing.
- 02
Check the curve
The chart shows the size at every width: flat at the min size, a straight rise, flat at the max size. Move the Viewport slider to preview the text at any width, or resize your browser to see the real CSS work.
- 03
Copy the CSS
Press Copy for a CSS declaration such as
font-size: clamp(...), or switch to Tailwind class for an arbitrary value class. Change the property field to use the same maths for padding, gaps or margins.
How the clamp() formula works
clamp(min, preferred, max) returns the preferred value, but never less than min or more than max. For fluid type, the preferred value is a straight line: a fixed part in rem plus a part that grows with the viewport in vw.
The generator finds that line from your two points. The slope is (maxSize - minSize) / (maxViewport - minViewport), and the fixed part is minSize - slope * minViewport. The fixed part is divided by the root size to get rem, and the slope is multiplied by 100 to get vw. For 16px at 320px wide to 24px at 1200px wide, that gives clamp(1rem, 0.8182rem + 0.9091vw, 1.5rem).
Why the output mixes rem and vw
A size in vw alone ignores the reader's font size setting, and it does not grow when they zoom in on a desktop browser. Keeping the min, the max and the fixed part in rem means the text still responds to the reader's settings. The vw part only adds the growth with screen width.
There is a limit. If the max size is far larger than the min size, browser zoom may not be able to make the text twice as large, which WCAG 1.4.4 asks for. The tool warns you when the max is more than about 2.5 times the min. Test with zoom at 200% either way.
Using fluid sizes in a real project
Pick one min and max viewport for the whole site, often 360px and 1280px, so every fluid size starts and stops growing at the same widths. Then make a small scale: body, small headings, large headings and section spacing, each with its own min and max.
Store each value as a CSS custom property, such as --step-0 for body text and --step-3 for an H2, and use the variables in components. If you still think in pixels, the px to rem converter helps with the min and max values.
Frequently asked questions
What does clamp() do in CSS?
clamp(min, preferred, max) picks the middle value: the preferred value, held between a lower and an upper limit. It works in any property that takes a length, such as font-size, padding, gap and width. It is supported in every current browser.
Can I use clamp() for spacing as well as type?
Yes. Type a different property in the CSS property field, such as padding-block, gap or margin-top, and the output uses it. Fluid spacing that uses the same min and max viewports as your type keeps the layout in proportion as the screen grows.
Is fluid typography accessible?
It can be. Keep the min and max sizes in rem so the reader's font size setting still applies, keep the ratio between max and min modest, and test with browser zoom at 200%. The generator writes rem values and warns you when the ratio is high.
How do I use the clamp() value in Tailwind CSS?
Switch the output to Tailwind class and copy it. For font-size you get a class such as text-[clamp(1rem,0.8182rem_+_0.9091vw,1.5rem)], where underscores stand for the spaces CSS needs around the plus sign. For a value you reuse, add it to your theme as a CSS variable instead.
Need this built into your site?
I build tools like this one, and the sites around them. Tell me what you need and I will reply with a plan and a fixed price.