Boneyard Tools

CSS clamp() Calculator for Fluid Type and Spacing

Scale a font size or spacing value smoothly between two viewport widths instead of stacking media queries. Enter the smallest and largest sizes with the breakpoints where each should apply, and the calculator draws the line between them and returns a ready-to-paste clamp() value in rem and vw. A live preview shows the computed size at the low, middle, and high viewport widths.

How to build a fluid clamp() value

  1. Enter the smallest size in the 'Min size' field and the viewport width in 'Min viewport' where it should apply.
  2. Enter the largest size in 'Max size' and the width in 'Max viewport' where it should reach that size.
  3. Adjust 'Root font size' if your project uses something other than the default 16px for rem conversion.
  4. Read the generated 'font-size: clamp(...)' block, plus the slope in vw and the intercept in rem below it.
  5. Scan the preview chips to confirm the computed pixel size at each sampled viewport width.
  6. Click 'Copy clamp()' to grab just the clamp() value and paste it into your stylesheet.

Examples

Fluid heading from 16px to 32px

min 16px at 320px, max 32px at 1280px
clamp(1rem, 0.6667rem + 1.6667vw, 2rem)

Fluid section spacing from 24px to 40px

min 24px at 375px, max 40px at 1440px
clamp(1.5rem, 1.1479rem + 1.5023vw, 2.5rem)

Bold hero size from 16px to 48px

min 16px at 320px, max 48px at 1440px
clamp(1rem, 0.4286rem + 2.8571vw, 3rem)

Frequently asked questions

What does CSS clamp() do?

clamp(min, preferred, max) returns the preferred value but never lets it drop below the min or rise above the max. When the preferred value includes a vw unit, it scales fluidly with the viewport, so one declaration replaces a stack of breakpoint media queries.

Why does the output mix rem and vw?

The rem part is a fixed base that respects the user's root font size, and the vw part adds growth tied to the viewport width. Added together they form the straight line that passes through your two size-and-breakpoint points.

How is the vw slope calculated?

The slope is (max size minus min size) divided by (max viewport minus min viewport), then multiplied by 100 to express it as a vw value. For 16px to 32px across 320px to 1280px that is 16 divided by 960 times 100, which rounds to 1.6667vw.

How is the rem intercept found?

The calculator computes the line's y-intercept in px as min size minus slope times min viewport, then divides by the root font size to convert to rem. For the 16px to 32px example the intercept is 10.6667px, which is 0.6667rem at a 16px root.

Can I change the root font size?

Yes. The 'Root font size' field defaults to 16px, matching most browsers. If your project sets a different root size, update the field so the rem numbers in the output convert against the correct base.

Can I use it for spacing, not just font sizes?

Yes. The math is identical for any length, so you can paste the clamp() value into margin, padding, gap, or width. The generated preview shows 'font-size:' as a sample declaration, but the clamp() value itself works for any property that accepts a length.

What if the size shrinks as the viewport grows?

That works too. When the max size is smaller than the min size the slope is negative, and the calculator still pins the clamp() bounds to the smaller and larger of the two values so the result stays clamped correctly at both ends.

Does clamp() stay accessible when users zoom?

Because the fixed base is expressed in rem, the value scales with the user's browser font-size preference and page zoom, which keeps fluid type readable. A purely vw-based value would ignore those settings, so the rem base matters for accessibility.

Why do the two viewports have to differ?

The slope divides by the gap between the two viewport widths, so identical widths would divide by zero and describe a vertical line with no single answer. The calculator reports an error and asks you to set two different breakpoints.

Learn more

Related tools