Home › Developer Tools › CSS Clamp Generator

CSS Clamp Generator

Generate a fluid CSS clamp() value that scales smoothly from a minimum size on small screens to a maximum size on large screens. Enter your sizes and viewport range to get ready-to-paste CSS, the math behind it, a size table for common breakpoints and an optional fluid type scale.

Last updated:

Size range
Viewport range
px
px
px

1rem in px (browser default 16)

e.g. font-size, padding, gap, margin

Optional fluid type scale

1.2 = minor third

1.333 = perfect fourth

Enter your values to see the result.
Advertisement
Advertisement

How to use the CSS Clamp Generator

  1. Enter the minimum and maximum size in px or rem.
  2. Set the viewport range where the size should grow, e.g. 320px to 1280px.
  3. Choose rem or px output and the property you are sizing.
  4. Copy the CSS from the result and paste it into your stylesheet.
  5. Optionally tick the type scale to get a full set of fluid heading sizes as CSS custom properties.

The clamp() formula

A fluid size is a straight line between two points: (minimum viewport, minimum size) and (maximum viewport, maximum size).

QuantityFormulaExample: 16→24px, 320→1280px
Slope(maxSize − minSize) ÷ (maxVw − minVw)8 ÷ 960 = 0.008333
Preferred vw partslope × 1000.8333vw
InterceptminSize − slope × minVw16 − 2.667 = 13.333px = 0.8333rem
CSSclamp(min, intercept + slope×100vw, max)clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem)

Common fluid type ranges

ElementMin → max (px)clamp() for 320px → 1280px
Body text16 → 18clamp(1rem, 0.9583rem + 0.2083vw, 1.125rem)
Lead paragraph18 → 22clamp(1.125rem, 1.0417rem + 0.4167vw, 1.375rem)
H320 → 28clamp(1.25rem, 1.0833rem + 0.8333vw, 1.75rem)
H224 → 36clamp(1.5rem, 1.25rem + 1.25vw, 2.25rem)
H132 → 56clamp(2rem, 1.5rem + 2.5vw, 3.5rem)

Popular type scale ratios: 1.125 (major second), 1.2 (minor third), 1.25 (major third), 1.333 (perfect fourth), 1.5 (perfect fifth) and 1.618 (golden ratio). Using a smaller ratio on phones and a larger one on desktops keeps headings from overwhelming small screens.

Frequently asked questions

How does CSS clamp() work?

clamp(MIN, PREFERRED, MAX) returns the preferred value but never less than MIN or more than MAX. For fluid type the preferred value mixes a fixed part and a viewport part, such as 0.8333rem + 0.8333vw, so the size grows linearly with the screen width between the two limits.

What is the formula for a fluid clamp value?

slope = (maxSize − minSize) ÷ (maxViewport − minViewport); intercept = minSize − slope × minViewport; preferred value = intercept + slope × 100vw. For 16px to 24px between 320px and 1280px: slope = 8 ÷ 960 = 0.008333, intercept = 13.333px, giving clamp(1rem, 0.8333rem + 0.8333vw, 1.5rem).

Why use rem instead of px in clamp()?

rem values scale with the font size the user sets in their browser, so the text respects their preference. A clamp() made only of px and vw ignores that setting. Keeping a rem part in the preferred value also lets browser zoom enlarge the text.

Is fluid typography accessible?

It can be, but sizes driven mostly by vw do not grow when users zoom. A common rule of thumb is to keep the maximum size at no more than about 2.5 times the minimum, and to include a rem component, so 200% zoom (WCAG 1.4.4) still works.

Which browsers support clamp()?

All modern browsers: Chrome and Edge 79+, Firefox 75+ and Safari 13.1+. It is safe to use in production today.

Can I use clamp() for spacing too?

Yes. clamp() works with any length property, such as padding, margin, gap, width or border-radius. Change the CSS property field and the tool writes the full declaration.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

PX to REM ConverterConvert px to rem or em and back, with a 1-100px table and a whole-CSS converter.PX to VW ConverterConvert pixels to vw and vh for any viewport size, and vw/vh back to px, with breakpoint tables.PX to EM ConverterConvert pixels to em using the parent font size, and em back to px, with conversion tables.CSS Gradient GeneratorDesign linear, radial and conic CSS gradients with draggable stops and export CSS or PNG.Open Graph PreviewPaste OG tags and preview how links look on Facebook, X and LinkedIn.YouTube Embed Code GeneratorCreate responsive YouTube embed code with start time, autoplay, loop and privacy mode.CSS Box Shadow GeneratorDesign layered CSS box shadows with a live preview, presets and one-click Copy CSS.CSS Border Radius GeneratorRound each corner, draw elliptical 8-value radii or random blob shapes and copy the CSS.CSS Button GeneratorDesign CSS buttons with gradients, borders, shadows and hover and active states, then copy the code.CSS Flexbox GeneratorBuild flexbox layouts visually: set container and item properties, then copy the CSS and HTML.Twitter Card GeneratorCreate X / Twitter Card meta tags with Open Graph fallbacks, character counters and a live preview.CSS Grid GeneratorDraw CSS grid layouts: set tracks and gaps, drag to name areas, then copy the CSS and HTML.Glassmorphism CSS GeneratorDesign frosted-glass UI cards with blur, transparency and border sliders, then copy the CSS.CSS Text Shadow GeneratorLayer CSS text shadows with a live preview and neon, 3D, outline and retro presets.HTML Editor (Live Preview)Write HTML, CSS and JavaScript and see a live, sandboxed preview as you type.HTML to JSX ConverterConvert HTML to valid React JSX: className, htmlFor, style objects, self-closing tags and events.CSS Clip-Path GeneratorDraw CSS clip-path shapes by dragging points: polygons, circle, ellipse and inset. Copy the CSS.CSS Animation GeneratorCreate CSS keyframe animations from 23 presets with live preview, timing controls and Copy CSS.CSS Triangle GeneratorMake CSS triangles in 8 directions with the border trick or clip-path. Set size and color, copy CSS.CSS Loader GeneratorPick from 14 pure CSS spinners and loaders, set color, size and speed, then copy the HTML and CSS.Cubic Bezier GeneratorDrag the control points to design a CSS easing curve, compare it with linear and copy cubic-bezier().CSS Filter GeneratorAdjust blur, brightness, contrast, hue, sepia and drop-shadow on an image and copy the CSS filter.CSS Specificity CalculatorCalculate CSS selector specificity (a, b, c), including :is(), :not(), :has() and :where(), and compare.Google Maps Embed GeneratorTurn an address or coordinates into responsive Google Maps iframe embed code, no API key.Neumorphism CSS GeneratorDesign soft UI neumorphic shapes with live preview and copy the box-shadow CSS.SVG Wave GeneratorMake layered SVG waves for section dividers and export SVG, PNG or a CSS background.SVG Blob GeneratorGenerate random organic SVG blob shapes with gradients and export SVG, PNG or CSS clip-path.CSS @font-face GeneratorTurn font files or URLs into ready-to-paste @font-face rules with weights, styles and a preview.CSS Media Query GeneratorBuild @media rules for widths, orientation, dark mode and hover, or get framework breakpoints.CSS Scrollbar GeneratorStyle scrollbars: width, colors, radius and hover, with ::-webkit-scrollbar and scrollbar-color CSS.CSS Sprite GeneratorPack many icons into one sprite sheet PNG and get CSS classes with background-position.CSS Text Gradient GeneratorMake gradient text with background-clip:text: color stops, angle, font preview and fallback CSS.CSS Toggle Switch GeneratorDesign pure-CSS toggle switches: size, colors, shape and animation. Copy accessible HTML + CSS.CSS Tooltip GeneratorBuild pure CSS tooltips: position, arrow, colors, padding and animation. Copy HTML and CSS.HTML Form BuilderDrag and drop form fields with labels and validation, then copy accessible HTML and CSS code.Iframe GeneratorCreate iframe embed code: size or responsive ratio, border, allow, sandbox, lazy load, live preview.SVG Path EditorEdit an SVG path d attribute visually: drag points, edit commands, convert, scale and minify.SVG to CSS Data URITurn SVG code into a small URL-encoded data URI for CSS backgrounds, with Base64 size comparison.Web App Manifest GeneratorCreate a PWA manifest.json and every app icon size from one image, downloaded as a ZIP.CSS Background Pattern GeneratorMake pure-CSS stripes, dots, checkerboard, zigzag and grid backgrounds and copy the code.CSS Color Filter GeneratorTurn a HEX color into a CSS filter that recolors black icons and SVGs, with an accuracy score.CSS Gradient Animation GeneratorCreate animated gradient backgrounds: pick colors, angle and speed, preview live and copy the CSS.CSS Hover Effects GeneratorPick button, link and image hover effects, tweak colors and timing, and copy the HTML and CSS.CSS InlinerMove CSS from style blocks into inline style attributes so HTML emails render in every client.CSS Shape Divider GeneratorCreate wave, tilt, curve and triangle section dividers and copy the SVG, HTML and CSS.CSS Transform GeneratorRotate, scale, skew and translate an element with sliders and copy the CSS transform code.Font Pairing ToolPreview Google Font heading and body pairs on real layouts and copy the embed code and CSS.HTML Accessibility CheckerPaste HTML to find WCAG accessibility problems with impact level, the failing element and a fix.HTML Image Map GeneratorDraw clickable rectangle, circle and polygon hotspots on an image and get image map HTML.SVG ViewerOpen or paste SVG code to preview it live with zoom, backgrounds, size info and PNG export.Pathfinding VisualizerAnimate BFS, DFS, Dijkstra, A* and greedy search on a grid with walls, weights and mazes.SVG to JSXTurn SVG code into a clean React component: camelCase attributes, style objects, TypeScript.Tailwind CSS Cheat SheetSearchable Tailwind class to CSS reference with live previews, class decoder and color palette.
See all 52 Web, HTML & CSS Tools →