Productivity and Utilities

CSS Clamp Generator

Create a fluid clamp() value that grows from a small size to a large size between two widths.

Your numbers

The size used at and below the small viewport width.

The size used at and above the large viewport width.

Used to write the sizes in rem. Browsers start at 16 px.

Result

CSS value

clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem)

16 px at 320 px wide to 24 px at 1,280 px wide

Slope
0.8333vw
Intercept
13.3333 px
Example rule
font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);

Resulting size at common widths

ViewportSize
320 px16 px
480 px17.33 px
768 px19.73 px
1024 px21.87 px
1280 px24 px
1920 px24 px
How this was calculated
  1. Slope = (largest - smallest) / (large width - small width) = (24 - 16) / (1,280 - 320) = 0.008333 px per px of width.
  2. Intercept = smallest - slope x small width = 16 - 0.008333 x 320 = 13.3333 px, which is 0.8333 rem.
  3. Preferred value = intercept + slope x 100vw = 0.8333rem + 0.8333vw. clamp() keeps it between 1 rem and 1.5 rem.
  • The rem part keeps text scalable when a visitor changes their browser font size. A value built from vw alone does not scale with browser zoom in the same way, so test it at a large text setting.

Calculated using SumPanda.com · https://sumpanda.com/css-clamp-generator/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the css clamp generator

  1. Enter the smallest size and largest size in pixels.
  2. Enter the small viewport width where the smallest size should end and the large viewport width where the largest size should start.
  3. Keep the root font size at 16 px unless your page sets another one, so the result is written in rem.
  4. Copy the clamp() value, or the example rule, into your CSS. The table shows the size at common screen widths.

Formula

slope = (largest - smallest) / (large width - small width)

intercept = smallest - slope x small width

clamp(smallest, intercept + slope x 100vw, largest)

Sizes and widths are in pixels. The intercept is converted to rem by dividing by the root font size, and the slope becomes a vw value by multiplying by 100. Numbers are shown to four decimals with zeros trimmed.

16 px to 24 px between 320 px and 1280 px

The slope is (24 - 16) / (1280 - 320) = 8 / 960 = 0.008333 pixels per pixel of width, which is 0.8333vw. The intercept is 16 - 0.008333 x 320 = 13.3333 px, which is 0.8333 rem. The result is clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem).

At a 768 px screen the size is 13.3333 + 0.008333 x 768 = 19.73 px, at 1024 px it is 21.87 px, and from 1280 px up it stays at 24 px. Below 320 px it stays at 16 px.

What clamp() does

clamp(min, preferred, max) returns the preferred value, but never less than min or more than max. When the preferred value is a rem amount plus a vw amount, the size grows in a straight line as the viewport widens, then stops at the two ends. That gives fluid type and spacing without a stack of media queries.

If the largest size is smaller than the smallest, the sizes shrink as the screen widens. The generator then puts the lower size first in the clamp(), because the first argument is the floor.

Accessibility note

A size that depends only on vw does not respond to the browser's zoom and text size settings the way rem does. Writing the intercept in rem keeps part of the value tied to the visitor's chosen font size, but the vw part still scales with the window. After you apply a clamp(), test it at a larger text setting and at 200% zoom.

If the two sizes are equal there is nothing to scale, so the tool asks for one fixed size instead. For converting sizes between units see the CSS unit converter, and for layouts see the CSS grid generator and the aspect ratio calculator.

Assumptions and limits

  • Viewport width means the width in CSS pixels that vw is measured against.
  • The root font size you enter is used to write the result in rem.
  • The scaling is a straight line between the two widths, and the size is held constant outside them.
  • Browser support for clamp() is assumed. Test in the browsers you care about.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

How do I make fluid font sizes with clamp()?

Choose the smallest and largest sizes and the two screen widths. The generator works out the rem and vw parts of the middle value so the size grows evenly between the widths.

Why is there a rem part in the middle value?

A straight line between two points has a slope and a starting offset. The vw term is the slope, and the rem term is the offset, so the line passes through both of your sizes.

Can the sizes get smaller on wider screens?

Yes. Enter a largest size that is lower than the smallest size. The tool swaps the outer values so the lower one is first.

Does clamp() work for spacing too?

Yes. It works for any length, such as margin, padding, gap or width. Enter the pixel sizes you want at each end.