Toolstia / CSS clamp generator

CSS clamp generator

Enter the smallest and largest size and the screen widths they apply at. The tool builds a clamp() value that grows smoothly in between, ready to paste into your CSS.

clamp(min, preferred, max) lets a size grow smoothly with the screen width but never go below the smallest or above the largest size. The preferred value is a straight line through your two points. Use it for font sizes, padding and margins, for example font-size: clamp(...).

How it works

  1. Enter the smallest and largest size in pixels.
  2. Enter the viewport widths for each.
  3. Copy the clamp() value.

What clamp does

clamp(min, preferred, max) picks the preferred value but never goes below the minimum or above the maximum. The preferred part uses vw units so it changes with the screen.

The math

The tool finds the straight line through your two points and writes it as a rem value plus a vw value, so the size is exactly your minimum at the small width and your maximum at the large width.

Why use it

You get fluid type and spacing with one line of CSS, and no media queries for each breakpoint.

Accessibility

The rem part lets the size respond to the user’s font size setting. Keep the maximum no more than about 2.5 times the minimum so text can still be zoomed.

Questions

Can I use it for spacing as well as fonts?

Yes, anywhere CSS accepts a length, such as padding, margin, gap or width.

Do all browsers support clamp?

Yes, all current browsers support it.

Is my data stored?

Everything happens in your browser, and nothing you enter is sent anywhere.