CSS clamp() Generator | Calculate the rem + vw clamp() from Minimum and Maximum Font Sizes and Viewport Widths, Fluid Type Scale CSS Variables, Find How Many px a Pasted clamp() Gives at Each Viewport Width, and Check Zoom (WCAG 1.4.4)

The CSS clamp() Generator answers questions such as “what font-size clamp() gives 16px on phones and 24px on desktops?”, “how do I calculate the vw value in clamp()?”, “how many px is clamp(1rem, 0.8239rem + 0.7512vw, 1.5rem) at a 768px viewport?” and “how do I make all my heading sizes fluid at once?”. Enter the size on small and large screens (px or rem) and the viewport range to scale across (such as 375 to 1440px), and it calculates the slope (the vw coefficient) and the intercept, then gives the CSS clamp(minimum, intercept rem + coefficient vw, maximum) and a Tailwind CSS arbitrary-value class. It works for padding, margin, gap and width as well as font-size, and comes with a preview and graph you can drag across viewport widths and a table of sizes at phone, tablet and desktop widths. It warns when the maximum is more than 2.5 times the minimum, so text may not double in size when zoomed (WCAG 1.4.4). The type scale tab turns a base size and a ratio (1.2, 1.25, the golden ratio and others) into a full set of heading sizes as clamp() CSS variables, and the read tab shows how many px a pasted clamp() gives at each viewport width and at which widths it reaches its minimum and maximum.

Make clamp() from minimum and maximum sizes

Enter the size on small and large screens to make a clamp() that scales smoothly with the viewport width in between.

Input unit

Viewport range (scales smoothly in between)

Output unit

CSS

font-size: clamp(1rem, 0.8239rem + 0.7512vw, 1.5rem);

Tailwind CSS

text-[clamp(1rem,0.8239rem+0.7512vw,1.5rem)]

Minimum (small screens)

1rem

16px / 1rem

Maximum (large screens)

1.5rem

24px / 1.5rem

vw coefficient (slope)

0.7512vw

0.751px per 100px of viewport width

Intercept (at viewport width 0)

0.8239rem

13.183px

Preview (drag the viewport width)

18.95px at a 768px viewport

A heading that scales Aa

3207681280192001326

The maximum is 1.5 times the minimum (within 2.5 times). Zooming the browser to 500% at least doubles the text at every viewport width (the usual guideline for WCAG 1.4.4).

Size by viewport width

The size at common viewport widths (phones, tablets and desktops).

Viewport widthpxremState
320px161Minimum
375px161Minimum
390px16.111.007Fluid
430px16.411.0258Fluid
768px18.951.1845Fluid
1024px20.881.3047Fluid
1280px22.81.4249Fluid
1440px241.5Maximum
1920px241.5Maximum

clamp(minimum, preferred, maximum) is a CSS function that keeps the preferred value (rem + vw) between the minimum and the maximum, and works in all major browsers. vw is based on the viewport width including the scrollbar, so the actual result may differ slightly.

ABOUT

About CSS clamp() Generator | Calculate the rem + vw clamp() from Minimum and Maximum Font Sizes and Viewport Widths, Fluid Type Scale CSS Variables, Find How Many px a Pasted clamp() Gives at Each Viewport Width, and Check Zoom (WCAG 1.4.4)

The CSS clamp() Generator is a free tool that builds a CSS clamp() (rem + vw) that scales smoothly with the viewport width, from the font size you want on small and large screens (px or rem) and a viewport range. It also gives Tailwind CSS classes, a fluid type scale for headings as CSS variables, works out how many px a pasted clamp() gives at each viewport width, and checks browser zoom (WCAG 1.4.4).

How to use CSS clamp() Generator | Calculate the rem + vw clamp() from Minimum and Maximum Font Sizes and Viewport Widths, Fluid Type Scale CSS Variables, Find How Many px a Pasted clamp() Gives at Each Viewport Width, and Check Zoom (WCAG 1.4.4)

  1. 1On the Make clamp() tab, enter the size on small screens and on large screens (px or rem)
  2. 2Choose the viewport range to scale across (such as 375 to 1440px), the root font size (usually 16px) and the output unit (rem or px)
  3. 3Copy the CSS or the Tailwind class, and check the size on phones and desktops with the preview and the table of sizes by viewport width
  4. 4To make all your headings fluid, use the Type scale tab to build CSS variables from a base size and a ratio
  5. 5To check an existing site's clamp(), paste it into the Read clamp() tab to see how many px it gives at each viewport width

Great for

  • When you want a font-size that changes with the viewport width, such as 16px on phones and 24px on desktops
  • When you want headings or spacing (padding, margin, gap) to scale smoothly without stacking several media queries
  • When you want to work out the vw value for clamp() from the phone and desktop font sizes in a design mockup
  • When you want to make h1 to h6 and small notes fluid all at once with a consistent ratio
  • When you want to know how many px another site's or a template's clamp() gives at 375px or 1440px

Good to know

  • clamp(minimum, preferred, maximum) is a CSS function that keeps the preferred value between the minimum and the maximum. Making the preferred value “rem + vw” lets it grow in proportion to the viewport width while stopping at the minimum on small screens and at the maximum on large screens.
  • The vw coefficient is the slope (the difference in size divided by the difference in viewport width) times 100. To go from 16 to 24px across viewport widths of 375 to 1440px, the slope is (24 - 16) ÷ (1440 - 375) ≈ 0.007512, so 0.7512vw, and the intercept is 16 - 0.007512 × 375 ≈ 13.18px (0.8239rem), giving clamp(1rem, 0.8239rem + 0.7512vw, 1.5rem). At a 768px viewport it is about 18.95px.
  • If the preferred value is vw alone, text does not grow when the browser is zoomed and the user's font size setting has no effect. Keep a rem part, and write the minimum and maximum in rem too. Keeping the maximum within 2.5 times the minimum means that zooming to 500% at least doubles the text at every viewport width, which meets the usual guideline for WCAG 1.4.4 (text can be resized to 200%).
  • A type scale sets heading sizes by multiplying the body text's base size by a ratio. Using a different ratio for small and large screens, such as 1.2 (Minor Third) and 1.25 (Major Third), keeps headings from getting too big on phones while giving a clear difference on desktops.
  • vw is 1/100 of the viewport width including the scrollbar. On desktop screens with a scrollbar, it is calculated from a width slightly larger than the visible area.

Questions this tool answers

Use CSS clamp() Generator | Calculate the rem + vw clamp() from Minimum and Maximum Font Sizes and Viewport Widths, Fluid Type Scale CSS Variables, Find How Many px a Pasted clamp() Gives at Each Viewport Width, and Check Zoom (WCAG 1.4.4) for searches like these:

  • css clamp font size calculator
  • how to calculate vw in clamp
  • clamp generator online
  • font size that scales with viewport width css
  • responsive font size clamp
  • clamp value in px
  • fluid type scale clamp generator
  • tailwind clamp font size
  • clamp accessibility zoom

FAQ

How do I calculate the vw value in clamp()?
(maximum size - minimum size) ÷ (maximum viewport width - minimum viewport width) × 100 is the vw coefficient, and minimum size - slope × minimum viewport width is the rem part (the intercept). To scale 16 to 24px across 320 to 1280px, that is 8 ÷ 960 × 100 ≈ 0.8333vw with an intercept of 13.33px, giving clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem).
How do I write a font-size that is 16px on phones and 24px on desktops?
Scaling across viewport widths of 375 to 1440px, it is font-size: clamp(1rem, 0.8239rem + 0.7512vw, 1.5rem);. It stays at 16px at 375px and below and at 24px at 1440px and above, and changes smoothly in between (about 18.95px at 768px, for example).
How many px does a clamp() size come to at each viewport width?
Convert the rem in the preferred value to px (1rem = 16px), add the vw coefficient × viewport width ÷ 100, and keep the result between the minimum and the maximum. clamp(16px, 4vw, 32px) is 16px up to a 400px viewport, 32px from 800px, and 24px at 600px. Paste it into the Read clamp() tab to see a full list.
Is a clamp() font size a problem for accessibility?
If the preferred value has a rem part and the maximum is within 2.5 times the minimum, text grows enough when the browser is zoomed. With a big difference such as 16 to 48px (3 times), there are viewport widths where zooming to 500% only makes the text about 1.67 times larger, which may fail WCAG 1.4.4, so this tool shows a warning.
How do I use clamp() in Tailwind CSS?
Write it as an arbitrary-value class with the spaces removed: text-[clamp(1rem,0.8239rem+0.7512vw,1.5rem)] for font-size, or p-[clamp(...)] for padding. This tool lets you copy the class directly for font-size, padding, margin, gap and width.

ARTICLES

Guides for CSS clamp() Generator | Calculate the rem + vw clamp() from Minimum and Maximum Font Sizes and Viewport Widths, Fluid Type Scale CSS Variables, Find How Many px a Pasted clamp() Gives at Each Viewport Width, and Check Zoom (WCAG 1.4.4)