Skip to content

CSS Clamp Calculator

Enter a minimum size, a maximum size, and the viewport width range they should apply across, and get a ready-to-paste CSS clamp() value that scales smoothly between them — the fluid-typography formula worked out for you instead of by hand.

  • Output in rem or px
  • Shows the computed slope
  • Validates min/max and viewport ranges
  • Runs fully client-side

Calculator

Calculated locally, nothing uploaded

font-size

How to calculate a CSS clamp() value

  1. 01

    Set the min and max size

    The smallest and largest the value should ever be, in px.

  2. 02

    Set the viewport range

    The viewport widths, in px, between which the value should scale.

  3. 03

    Copy the clamp() value

    Paste it directly as a font-size, padding, or any other length property.

What clamp() actually does#

clamp(min, preferred, max) picks the middle value clamped between the other two — it grows or shrinks with the preferred value (usually viewport-relative) but never goes below the min or above the max. The tricky part isn't the clamp() syntax itself, it's the preferred value in the middle: a vw-based expression whose coefficient has to be calculated from the actual slope between your min and max sizes across your chosen viewport range, and that's the part this tool works out.

Why the middle term looks like "1rem + 2.5vw", not a plain vw#

A pure vw value scales to zero at a zero-width viewport, which is never actually what you want — you want a size that scales but never collapses. The formula adds a fixed offset (the point where the line defined by your two size/viewport pairs would cross a zero-width viewport) to a vw term, so the two together reproduce a straight line that passes exactly through your min size at your min viewport and your max size at your max viewport.

rem versus px for the output#

rem output respects a user's browser font-size setting — someone who has bumped their default text size up gets a proportionally larger clamp() range too, which is the accessible default. px output is exact and predictable but ignores that setting entirely; it makes sense for things like a fixed-width icon or spacing value that genuinely should not respond to text-size preferences.

Frequently asked questions

Why is the middle value "1rem + 2.5vw" instead of just a vw value?

A pure vw value shrinks to zero on a zero-width viewport, which is never the intent. Adding a fixed offset produces a straight line that passes exactly through your min size at your min viewport and your max size at your max viewport, instead of one that collapses toward zero.

Should I use rem or px for the output?

rem respects a user's browser font-size setting, which is the accessible default for text. px is exact but ignores that setting — reasonable for a value that genuinely should not scale with text-size preferences.

What if my max size needs to be smaller than my min size at some point?

clamp() only supports a single linear scale between one min and one max — it cannot express a non-monotonic curve. That would need multiple clamp() rules behind a media query instead.

Is my data sent anywhere?

No. The calculation runs entirely in your browser.

Developers

UUID Generator

Generate cryptographically random UUID v4 or time-ordered UUID v7, in bulk.

Developers

Base64 Encoder & Decoder

Encode and decode Base64 with correct UTF-8 handling, including the URL-safe alphabet.

Developers

ULID Generator

Generate ULIDs — sortable by creation time like UUID v7, but Crockford Base32 instead of hex.