CSS clamp() Calculator

Build fluid font sizes and spacing with clamp().

Your input

px
px
px
px
px
clamp(1rem, 0.6667rem + 1.6667vw, 2rem)
1 lines · 39 bytes
  • Grows 1.6667vw per 1vw of viewport, from 320 px to 1,280 px wide; below and above that the size stays at 1rem and 2rem. Using rem keeps the text responding to a user’s own font-size setting.

Size at each viewport width

ViewportSize (px)Size (rem)
320 px161
480 px18.671.167
768 px23.471.467
1,024 px27.731.733
1,280 px322
1,536 px322

What is CSS clamp()?

The CSS clamp() function picks a value between a minimum and a maximum, with a preferred value in the middle. For type it lets a size grow smoothly as the screen gets wider, then stop at a limit. You get fluid text without writing media queries.

A common form is clamp(1rem, 0.6667rem + 1.6667vw, 2rem). That means: never smaller than 1rem, never larger than 2rem, and in between grow by 1.6667% of the viewport width plus a fixed part. This tool works out that middle part from the sizes and screen widths you choose, and also shows a table of the size at common widths.

Formula

slope = (max − min) ÷ (maxViewport − minViewport); intercept = min − slope × minViewport; value = clamp(min, intercept + slope × 100vw, max).

How to use the CSS clamp() Calculator

  1. Enter the smallest and largest size.
  2. Enter the screen widths where growth starts and stops.
  3. Choose rem or px output.
  4. Copy the clamp() value into your CSS.

Real situations

When people use the CSS clamp() Calculator

  • 1

    Fluid headings

    Let a heading grow from 24 px on phones to 48 px on desktops without breakpoints.

  • 2

    Responsive spacing

    Use the same method for padding and gaps so layouts breathe on larger screens.

  • 3

    Check the size at a given width

    Read the table to see exactly how large the text will be at 768 or 1024 pixels wide.

  • 4

    Convert between rem and px

    Switch the output between rem and px depending on your project's conventions.

Good to know

  • Test the result with browser zoom, since pure vw sizes can ignore it.

FAQ

CSS clamp() Calculator: questions answered

What does the default example give?

A size from 16 px at a 320 px screen up to 32 px at 1280 px produces clamp(1rem, 0.6667rem + 1.6667vw, 2rem), with a 16 px root. At 768 px wide the size is 23.47 px.

Why use rem instead of px?

Rem units follow the user's browser font setting, so text still scales if someone has chosen a larger default. Pure px values do not. Using rem in the minimum and maximum keeps this respect for user choice.

How is the middle value calculated?

The slope is (max − min) ÷ (largest width − smallest width). The intercept is min − slope × smallest width. The preferred value is intercept + slope × 100vw.

Can the size shrink as the screen grows?

Yes. If your largest size is smaller than the smallest, the tool writes a negative slope with a minus sign. It is valid CSS.

What is the root font size setting for?

It converts pixels to rem. Browsers default to 16 px, so 32 px is 2rem. Change it only if your project sets a different root size.

Does clamp() work in all browsers?

It is supported by all current major browsers. Older browsers that do not know it will ignore the declaration, so set a fixed fallback value on the line before if you need to support them.

How does the CSS clamp() Calculator work?

slope = (max − min) ÷ (maxViewport − minViewport); intercept = min − slope × minViewport; value = clamp(min, intercept + slope × 100vw, max). Results update as you type.

Is this CSS clamp() Calculator free and private?

Yes. It is free with no sign-in, and every calculation runs inside your browser. Nothing you type is sent to a server or stored, and the page keeps working offline once it has loaded.

Private by design. No accounts, no cookies, no tracking. Everything you type stays on your device.

How we keep it that way