CSS clamp calculator for fluid typography

CSS clamp() sets a value that grows with the screen but stays between a minimum and a maximum: clamp(min, preferred, max). For fluid type, the preferred value mixes rem and vw, for example clamp(1rem, 0.5rem + 2vw, 2rem).

Turn a minimum and maximum font size into one responsive clamp() value that scales between two viewport widths.

Your clamp() expression

font-size: clamp(1rem, 0.6667rem + 1.6667vw, 2rem);

At 800px wide the text renders at 24px.

Fluid type scales smoothly between screen sizes.

Worked example: 16px to 32px

Text that should be 16px on a 320px phone and 32px on a 1280px desktop, with a 16px root font size, gives:

font-size: clamp(1rem, 0.6667rem + 1.6667vw, 2rem);
Viewport widthRendered size
320px or narrower16px (1rem minimum)
800px24px
1280px or wider32px (2rem maximum)

How the clamp() formula works

The slope is the size change divided by the width change: (32 − 16) ÷ (1280 − 320) = 0.016667, which is 1.6667vw. The intercept is the size at a zero-width viewport: 16 − 0.016667 × 320 = 10.667px, or 0.6667rem. The preferred value 0.6667rem + 1.6667vw draws a straight line between your two points, and clamp() stops it at the minimum and maximum.

Need the sizes first? Build them with the type scale generator.

Zoom and root font size limits

The rem parts follow the visitor's root font size, but the vw part follows only the viewport width. If a visitor raises their default font size, the result is no longer exactly the px values above. Browser zoom shrinks the CSS viewport, so a large vw share can limit how much text grows when zoomed. Keep the gap between minimum and maximum modest and check that text still reaches 200% at 200% browser zoom (WCAG 1.4.4 Resize Text).

Choose the fonts to scale

Find typefaces used on real websites, then size them with the calculator.

Frequently asked questions

Should I use rem or px in clamp()?

Use rem for the minimum, maximum and fixed part of the preferred value. Rem values follow the visitor's browser font-size setting, while px values ignore it. The calculator takes px inputs because designs are usually specified in px, then converts them using the root font size you enter.

How is the middle value of clamp() calculated?

The calculator draws a straight line between your two points. The slope is the font size change divided by the viewport width change, written in vw by multiplying it by 100. The intercept is the minimum size minus the slope times the minimum width, written in rem. Together they form the preferred value, such as 0.6667rem + 1.6667vw.

What happens if the minimum and maximum viewport widths are equal?

Then there is no range to scale across, and the slope calculation would divide by zero. The calculator asks for two different widths instead of producing a broken value. If you want the text to stay one size at every width, set font-size directly to a rem value and skip clamp() entirely, because there is nothing for it to clamp.

What if the maximum font size is smaller than the minimum?

CSS clamp() returns the minimum whenever the minimum is larger than the maximum, so the text would stay at one size and never scale. The calculator flags reversed values instead of producing that expression. Enter the size you want on narrow screens as the minimum and the size you want on wide screens as the maximum.

More typography & unit tools

Color tools

Image tools

CSS generators

Image & SVG tools

More free tools

All free tools