ZapKit

CSS clamp() Generator for Fluid Sizes

Make text and spacing grow smoothly from mobile to desktop: give a size for the smallest and largest screens, and get a clamp() that scales between them.

What is a CSS clamp() generator?

A clamp() generator writes fluid CSS: values that grow gradually with the screen width instead of jumping at media-query breakpoints. Fluid typography keeps headings proportional on every device, from a small phone to a wide monitor, with a single line of CSS.

Enter the size you want at the smallest and largest screens and the viewport widths between which it should scale. The generator does the linear maths, writes the clamp() in rem and vw, and lets you drag a viewport slider to see the resulting size at any width.

How to use the CSS clamp() Generator for Fluid Sizes

  1. 1.Set the sizes

    The size you want on the smallest screen and on the largest, in pixels.

  2. 2.Set the viewports

    The screen widths where scaling starts and stops, and your root font size.

  3. 3.Copy and preview

    Copy the clamp() and drag the viewport slider to see the size at any width.

Example: 18 px to 32 px between 375 and 1280 px

With a 16 px root font size:

Slope
14 ÷ 905 = 0.01547 (1.547vw)
Intercept
12.2 px = 0.7624rem
CSS
font-size: clamp(1.125rem, 0.7624rem + 1.547vw, 2rem)
At 768 px wide
24.08 px

slope = (max − min) ÷ (max viewport − min viewport)

Below 375 px the text stays at 18 px and above 1280 px it stops at 32 px.

The maths

Between the two viewports the size follows a straight line: slope = (max size − min size) ÷ (max viewport − min viewport), and intercept = min size − slope × min viewport. The preferred value is intercept (in rem) + slope × 100 (in vw), clamped between the minimum and maximum sizes.

Sizes are written in rem so they respect the reader's browser font-size setting, which matters for accessibility. Very steep slopes can stop text growing when users zoom, so keep the range modest for body text.

Frequently asked questions

What does clamp() do?

clamp(min, preferred, max) uses the preferred value but never goes below min or above max.

Why rem instead of px?

rem follows the user's chosen base font size, so text still scales for people who set larger text in their browser.

Can I use it for spacing?

Yes. Change the property to padding, gap or margin.

Which viewport range should I use?

Around 375 px (a small phone) to 1280–1440 px (a laptop) suits most sites.

More Developer tools