Frontend ToolsA little help for every day

Search by name or task, such as JSON or percentage.

Frontend Tools

CSS clamp() Generator for Fluid Sizes

Generate a fluid CSS clamp() value from a minimum and maximum size and a viewport range, in rem or px, with a table of computed sizes at common screen widths.

View all tools
ResultUpdates as you type
font-size: clamp(1rem, 0.6667rem + 1.4815vw, 2rem);
Viewport widthComputed (px)Computed (rem)
320px161
360px161
375px16.221.0139
768px22.041.3778
1024px25.841.6148
1280px29.631.8519
1440px322
1920px322

How to use CSS clamp() Generator for Fluid Sizes

Enter the minimum and maximum sizes and the viewport widths where scaling starts and stops, then choose rem or px output, the root font size and the CSS property. Copy the declaration and check the size table.

  1. Set the size rangeEnter the minimum size for small screens and the maximum size for large screens, both in px.
  2. Set the viewport rangeChoose where scaling starts and stops, such as 360px and 1440px. Outside that range the size stays fixed.
  3. Pick the output and copyChoose rem or px, the root font size and a property such as font-size or gap, then copy the code.

How the preferred value is calculated

The middle value of clamp() is a straight line between two points. Slope = (max size − min size) ÷ (max viewport − min viewport), and slope × 100 gives the vw figure. The intercept is min size − slope × min viewport. For the defaults, 16px to 32px between 360px and 1440px, the slope is 16 ÷ 1080, giving 1.4815vw, and the intercept is about 10.6667px, or 0.6667rem with a 16px root: font-size: clamp(1rem, 0.6667rem + 1.4815vw, 2rem). At a 768px viewport that works out at about 22.04px.

rem, px and zoom accessibility

With rem output, the minimum, maximum and intercept are converted using the root font size, so text follows the user's browser font size setting. px output gives clamp(16px, 10.6667px + 1.4815vw, 32px), which ignores that setting. Because part of the value is in vw, zooming has less effect on it, and if the maximum is more than 2.5 times the minimum, text may not reach 200% when zoomed, as WCAG 1.4.4 requires; the tool warns you. If the small-screen size is the larger one, the value shrinks as the viewport grows.

Accuracy and data handling

After adding generated code to a project, test it in the target browsers and responsive sizes. The calculation runs in your current browser; the tool code does not send the input to a processing API.

Often Used Together

Next step

FAQ

What do the three values in CSS clamp() mean?

They are the minimum, the preferred value and the maximum. The browser works out the preferred value, such as 0.6667rem + 1.4815vw, and keeps the result between the minimum and the maximum.

How is the vw value in clamp() calculated?

vw = (max size − min size) ÷ (max viewport − min viewport) × 100. For 16px to 32px across viewports from 360px to 1440px, that's 16 ÷ 1080 × 100 ≈ 1.4815vw.

Which browsers support clamp()?

Chrome and Edge 79, Firefox 75 and Safari 13.1 onwards support clamp(), so every current major browser does. Internet Explorer never did.

More Frontend Tools

Related tools