CSS clamp calculator

With this CSS clamp calculator you turn a minimum and maximum value plus a viewport range into the finished clamp() expression for font sizes, spacing and widths, without any media queries.

Example: CSS property: font-size · Smallest value (mobile) 16 px · Largest value (desktop) 24 px · From viewport width 320 px · To viewport width 1,280 px · Base font size (rem) 16 px → CSS: font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);. Source: MDN – CSS clamp(): clamp(MIN, VAL, MAX). Updated: .

px
px
px
px
px
16 px
My ToolboxYour inputs are saved in this browser only.

Result

CSS
font-size: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem);
Value at common viewport widths
Viewport widthValue in pxValue in rem
320 px16 px1 rem
375 px16.46 px1.029 rem
768 px19.73 px1.233 rem
1024 px21.87 px1.367 rem
1280 px24 px1.5 rem
1920 px24 px1.5 rem
In between, the value grows linearly by 0.8333 vw for each 1 vw of viewport width.

How it is calculated

clamp(MIN, VAL, MAX) limits a value from below and above. For type that grows from 16 to 24 px between 320 px and 1280 px of viewport width, it reads: clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem).

How it is calculated

Between the two viewport widths the value rises linearly. The slope is (max − min) / (viewportmax − viewportmin), the intercept is min − slope · viewportmin. The intercept is in rem and the slope in vw, so a browser font size enlarged by the user still counts. The table shows the value you get on typical devices.

Good to know

Frequently asked questions

How do I calculate clamp() for font sizes?

Enter the minimum and maximum size in px and the viewport widths. The calculator builds the preferred value from rem and vw and sets it between minimum and maximum.

Why does the expression contain a rem part?

A value in vw alone ignores the browser font size. With a rem part the text still scales for users with a larger default size.

Can I use clamp() for spacing too?

Yes, for any CSS property that takes a length, such as padding, margin, gap or width.

What does 1.5rem at the end mean?

The maximum: above the upper viewport width the type stops growing. At a 16 px base, 1.5 rem is exactly 24 px.

Sources and legal basis

As of: · Editorial policy

Related tools