Skip to content
Motion and CSS

CSS clamp() Calculator

Set a smallest and largest size and two viewport widths, see the result at any width, and copy clamp() as CSS or Tailwind.

Last checked

Sizes and viewports

Unit
Grow with

Presets

The code

font-size: clamp(1rem, 0.8571rem + 0.7143vw, 1.5rem);
Slope
0.7143vw
Intercept
13.714px
Lower bound
1rem
Upper bound
1.5rem

Size at common widths

WidthSizeIn rem
320px16px1rem
375px16.39px1.024rem
480px17.14px1.071rem
768px19.2px1.2rem
1024px21.03px1.314rem
1280px22.86px1.429rem
1440px24px1.5rem
1920px24px1.5rem

Checked at 320, 375, 480, 768, 1024, 1280, 1440, 1920px. Below 320px the size stays at its smallest, above 1440px at its largest.

Preview at any width

Fluid type grows with the screen.

Fluid type scale

A full set of sizes, each one fluid between your two widths. The base is the 0 step. The scale settings are part of the share link.

StepSmallLargeZoomclamp()
--step--211.11px12.16pxOKclamp(0.6944rem, 0.6757rem + 0.0937vw, 0.76rem)
--step--113.33px15.2pxOKclamp(0.8333rem, 0.8rem + 0.1667vw, 0.95rem)
--step-016px19pxOKclamp(1rem, 0.9464rem + 0.2679vw, 1.1875rem)
--step-119.2px23.75pxOKclamp(1.2rem, 1.1187rem + 0.4063vw, 1.4844rem)
--step-223.04px29.69pxOKclamp(1.44rem, 1.3213rem + 0.5935vw, 1.8555rem)
--step-327.65px37.11pxOKclamp(1.728rem, 1.559rem + 0.8448vw, 2.3193rem)
--step-433.18px46.39pxOKclamp(2.0736rem, 1.8377rem + 1.1794vw, 2.8992rem)
--step-539.81px57.98pxOKclamp(2.4883rem, 2.1639rem + 1.6223vw, 3.624rem)

Fluid space scale

Spacing from the same base: 3xs is a quarter of it, 3xl six times. Pairs such as s-l run from one size on small screens to a bigger one on large screens, for gaps that open up more than the text.

NameSmallLargeclamp()
--space-3xs4px4.75pxclamp(0.25rem, 0.2366rem + 0.067vw, 0.2969rem)
--space-2xs8px9.5pxclamp(0.5rem, 0.4732rem + 0.1339vw, 0.5938rem)
--space-xs12px14.25pxclamp(0.75rem, 0.7098rem + 0.2009vw, 0.8906rem)
--space-s16px19pxclamp(1rem, 0.9464rem + 0.2679vw, 1.1875rem)
--space-m24px28.5pxclamp(1.5rem, 1.4196rem + 0.4018vw, 1.7813rem)
--space-l32px38pxclamp(2rem, 1.8929rem + 0.5357vw, 2.375rem)
--space-xl48px57pxclamp(3rem, 2.8393rem + 0.8036vw, 3.5625rem)
--space-2xl64px76pxclamp(4rem, 3.7857rem + 1.0714vw, 4.75rem)
--space-3xl96px114pxclamp(6rem, 5.6786rem + 1.6071vw, 7.125rem)
--space-3xs-2xs4px9.5pxclamp(0.25rem, 0.1518rem + 0.4911vw, 0.5938rem)
--space-2xs-xs8px14.25pxclamp(0.5rem, 0.3884rem + 0.558vw, 0.8906rem)
--space-xs-s12px19pxclamp(0.75rem, 0.625rem + 0.625vw, 1.1875rem)
--space-s-m16px28.5pxclamp(1rem, 0.7768rem + 1.1161vw, 1.7813rem)
--space-m-l24px38pxclamp(1.5rem, 1.25rem + 1.25vw, 2.375rem)
--space-l-xl32px57pxclamp(2rem, 1.5536rem + 2.2321vw, 3.5625rem)
--space-xl-2xl48px76pxclamp(3rem, 2.5rem + 2.5vw, 4.75rem)
--space-2xl-3xl64px114pxclamp(4rem, 3.1071rem + 4.4643vw, 7.125rem)
--space-s-l16px38pxclamp(1rem, 0.6071rem + 1.9643vw, 2.375rem)

How to use it

  1. Enter the smallest and largest font size and the viewport widths where they apply, or start from a preset.
  2. Move the viewport slider to see the size at any width, and read the table for common ones.
  3. Copy the CSS, the clamp() value or the Tailwind class. Use the type and space scale sections for a whole set of sizes, and pick the export format you need.

What it checks and why

clamp(min, preferred, max) keeps a value between two limits and lets it grow in between. For fluid type the preferred value is a straight line: a rem part plus a vw part, so the size rises from the smallest at one viewport width to the largest at another and holds there.

The calculator solves the line for you. The slope is the size range divided by the viewport range, and the intercept is what the line gives at a zero-width screen. Writing the rem part in rem, not px, keeps the browser's font size setting working.

Fluid type has an accessibility catch. The vw part does not grow when a visitor zooms the page, so text that grows a lot between the limits can stay too small at 200% zoom. The tool warns when the largest size is more than about 2.5 times the smallest, and checks every step of the type scale the same way.

Switch the unit to cqi and the value follows the width of the nearest container instead of the screen, which suits components that sit in columns of different widths. The space scale uses the same base: 3xs is a quarter of it and 3xl six times, and pairs such as s-l go from one size on small screens to a bigger one on large screens.

Specs and sources

Limits

  • Sizes are interpolated in a straight line between the two widths.
  • cqi needs an ancestor with container-type: inline-size; without one it falls back to the small viewport width. The preview slider stands for the container width in that mode.
  • The vw unit includes the width of a vertical scrollbar, so values differ by a few pixels from a layout that excludes it.
  • The 2.5 times limit is a rule of thumb, not a WCAG number. Test with browser zoom at 200%.

Questions

How does clamp() work for font size?
clamp(1rem, 0.857rem + 0.714vw, 1.5rem) means the size is at least 1rem, at most 1.5rem, and in between it follows 0.857rem plus 0.714% of the viewport width.
Should I use rem or px in clamp()?
Use rem. Pixel values ignore the font size a visitor sets in their browser. The calculator converts from px using your root font size, 16px by default.
Is fluid type accessible?
It can be, if the largest size is not much bigger than the smallest and the text still scales when a visitor zooms in. The warning in the tool flags the risky setups; test at 200% zoom.
What is a fluid type scale?
A set of sizes (small print, body, headings) where each step is a clamp() value. A ratio such as 1.2 or 1.25 sets the gap between steps, and it can be different on small and large screens.
Can I use clamp() for padding and spacing?
Yes. clamp() works for any length, so pick padding, margin, gap, width or height in the Property menu. The fluid space scale gives a whole set of spacing values that grow with the type.
How do I use clamp() with container query units?
Switch the unit to cqi. 1cqi is 1% of the inline size of the nearest container, so set container-type: inline-size on the parent. The two widths then mean container widths, not screen widths.
Why does my fluid text not grow when I zoom in?
Zoom makes the viewport narrower in CSS pixels, so the vw part shrinks while the rem part grows. Keep the largest size within about 2.5 times the smallest, so more of the value is rem, and test at 200% zoom.