CSS clamp() Generator

Generate a fluid CSS clamp() value that scales linearly between a minimum and a maximum size across a viewport range, for responsive typography and spacing. Enter sizes in pixels, choose rem or px output, start from presets such as Body text or Heading h1, and check the result with a live preview slider. Everything runs in your browser.

How to use

  1. Enter the minimum and maximum size in pixels, or click a preset.
  2. Set the minimum and maximum viewport widths between which the size should scale.
  3. Choose rem or px as the output unit; rem output assumes a 16px root font size.
  4. Drag the Live preview slider to check the size at different viewport widths, then click Copy value or Copy as font-size.

Example

Input

Minimum size: 16px · Maximum size: 24px
Minimum viewport: 320px · Maximum viewport: 1280px
Output unit: rem

Output

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

Live preview @ 800px → 20px

Frequently asked questions

How is the clamp() value calculated?

The middle expression is a straight line between your two points. With 16px at 320px and 24px at 1280px, the slope is 8 ÷ 960, or 0.8333vw, and the intercept is 13.3333px, or 0.8333rem. Outside the viewport range, the value stops at your minimum and maximum.

Should I use rem or px?

Prefer rem, so that users who change their browser font size still get a proportionally scaled value. The tool always assumes a 16px root font size, so the rem values will not line up if your site sets a different root size.

Is clamp() only for font sizes?

No. You can use the value for other length properties such as padding, margin or gap, and the Section spacing preset (16px to 48px) is meant for that. Copy value copies only clamp(...), while Copy as font-size copies a complete font-size declaration.

Why does the tool show an error instead of a value?

The minimum size must not be greater than the maximum size, and the minimum viewport must be smaller than the maximum viewport. Correct the input named in the message and the value reappears.

Related tools