CSS Free, no sign-up

CSS clamp() calculator

Enter the smallest and largest font size and the viewport widths they belong to — the tool works out the clamp() formula, plots font size against viewport width and gives you ready-made font-size CSS.

Result
Ready-made CSS
h1 {
  font-size: clamp(1rem, 0.6667rem + 1.6667vw, 2rem);
}

How to use it

  1. Enter the minimum and maximum font size in pixels, for example 16px on phones and 32px on wide screens.
  2. Set the viewport widths where scaling starts and stops — typically 320px and 1280px.
  3. Choose the output unit: rem (recommended) or px. For rem, check the root font size, usually 16.
  4. Drag the marker on the chart or move the “Simulated viewport width” slider — the sample heading is shown at the size that width produces. Click “Copy” to take the code.

How it works

How the formula works

The font size follows a straight line through two points: (minVw, min) and (maxVw, max). The slope is slope = (max − min) / (maxVw − minVw) and the offset is intercept = min − slope × minVw. In CSS the slope becomes a vw value: 1vw is 1% of the viewport width, so you write slope × 100. The result is clamp(min, intercept + slope×100vw, max): flat below the minimum width, a ramp in between, flat again above the maximum width.

font-size: clamp(1rem, 0.6667rem + 1.6667vw, 2rem);

Why rem belongs in the middle term

A size written only in vw (font-size: 2vw) does not grow when the user zooms the page: zooming shrinks the viewport measured in CSS pixels, so the text stays the same physical size. That fails WCAG 1.4.4 Resize Text, which requires text to be scalable up to 200%. The rem part reacts to zoom and to the font size set in the browser, and rem bounds scale too. A commonly cited rule of thumb is to keep the maximum within about 2.5 times the minimum.

min(), max() and clamp()

clamp(MIN, VAL, MAX) sets a floor and a ceiling at once and equals max(MIN, min(VAL, MAX)). min() gives only an upper cap, max() only a lower floor.

font-size: min(5vw, 3rem);   /* never above 3rem */
font-size: max(1rem, 2vw);   /* never below 1rem */

clamp() is not only for fonts

Any property that takes a length accepts it: padding, margin, gap, width. Fluid spacing keeps the layout in proportion with the type. For spacing a simple clamp(1rem, 5vw, 3rem) is often enough, while the middle term from the calculator helps when you need an exact ramp between two widths.

padding-inline: clamp(1rem, 5vw, 3rem);
gap: clamp(0.75rem, 2vw, 2rem);

FAQ

How is clamp() different from media queries for font size?

Media queries change the size in steps at breakpoints, while clamp() changes it smoothly at every pixel of width. You need fewer rules and fewer breakpoints. If the design calls for exact stepped sizes, media queries are still the better tool.

Which minimum and maximum viewport widths should I use?

The most common pair is 320px (a small phone) and 1280–1440px (a laptop or your container’s maximum width). Choose a maximum close to your content width, since the text stops growing beyond it. Keep in mind that vw includes the width of a classic scrollbar.

Should I output rem or px?

Prefer rem: it respects the font size set in the browser and keeps the text zoomable. Pixel values ignore the user’s font setting, so use px only as a deliberate choice.

Is clamp() supported by browsers?

Yes, by every modern browser since 2020 (Chrome 79, Firefox 75, Safari 13.1). For very old browsers write a plain font-size: 1.25rem; first and put the clamp() line after it — an old browser simply skips the line it does not understand.

This topic in the HTML & CSS course

More CSS tools

CSS gradient generator Linear, radial and conic gradients: pick colors, angle and stops, then copy the code. Flexbox generator and playground Try flex properties on a container and its items: direction, alignment, gaps and ready-made CSS. CSS Grid generator Set columns and rows, gaps and alignment, then copy the ready-made grid code. CSS box-shadow generator Pick offset, blur, color and layers for a shadow, then copy the ready-made box-shadow code. Cubic-bezier generator Drag the control points of an easing curve and copy the ready-made CSS transition. SVG animation generator Pick a shape and an effect — get inline SVG and CSS keyframes ready to paste. CSS specificity calculator Type selectors to see their (a,b,c) weight, a color-coded breakdown and which rule wins. CSS box model visualizer See content, padding, border and margin as a DevTools-style diagram and copy the CSS. CSS transform generator Move, rotate, scale and skew an element, see its original position and copy the code. Color contrast checker (WCAG) Check text and background contrast against WCAG AA and AAA, and fix a failing pair of colors. CSS clip-path generator Polygons, bevels, arrows and circles: drag control points on the live canvas and copy ready-made CSS. CSS glassmorphism generator Frosted glass effect: backdrop-filter blur, saturation, border highlight and clean CSS. CSS border-radius (Blob) generator Organic shapes and 8-value border-radius: tune horizontal and vertical corner radii. CSS Stacking Context & z-index Visualizer Why z-index: 9999 fails! Explore CSS Stacking Contexts in interactive 3D exploded layers with transform, opacity and isolation triggers. CSS aspect-ratio & object-fit Generator Eliminate squished images & CLS layout jumps: live aspect-ratio proportions and interactive object-position focal point. CSS Filters Studio & Generator Photo effects without design tools: blur, contrast, hue-rotate, sepia, and trending Instagram-style presets. OKLCH Color Picker & Palette Generator Perceptually uniform brightness & vibrant Display P3 colors: OKLCH picker, design system scales, and fallbacks. CSS Scroll-driven Animations Generator Scroll-linked animations without JavaScript: animation-timeline scroll() & view(), reading progress bar & reveal on scroll. CSS Container Queries (@container) Generator Beyond viewport media queries: components adapt directly to their parent container width. Live resizer & @container rules.
WhatsApp