CSS Clamp() Generator
Generate fluid, responsive clamp() values for typography and spacing. Set your min/max sizes and viewport breakpoints — get production-ready CSS instantly.
How to use
Pick a preset or configure manually
Start with a preset (Body Text, H1, Section Spacing…) to populate the fields instantly, or enter your own values. Presets follow industry-standard breakpoints and scale ratios.
Set sizes and viewport breakpoints
Enter the minimum size (at the smallest viewport) and maximum size (at the largest). Then set the viewport widths where the scaling should start and stop. 320px–1280px is a good default.
Choose a unit and CSS property
Select px, rem, or em. Use rem for font sizes to respect browser accessibility settings. Choose the CSS property — font-size, padding, margin, gap, width, and more are all supported.
Copy and use in your project
Copy the clamp() value, full CSS declaration, CSS variable, or Tailwind arbitrary value. Check the Value at Key Viewports table to verify the computed value across common device sizes before shipping.
When to use CSS clamp()
Fluid typography
Replace 3–5 font-size media query overrides with a single clamp() line. Text scales smoothly between mobile and desktop, fitting every viewport — not just the breakpoints you wrote.
Responsive section spacing
Section padding that works on a 320px phone and a 2560px monitor without breakpoints. clamp(2rem, 5vw, 8rem) gives tight mobile spacing and generous desktop breathing room.
Container widths
width: clamp(320px, 90vw, 1200px) is a clean, readable alternative to max-width + width: 100%. It constrains the width without needing a wrapping element or separate media query.
Touch-target sizing
Ensure interactive elements scale from minimum accessible touch targets (44px) on mobile to comfortable click targets on desktop, without abrupt jumps at breakpoints.
Display headings
Hero and display headings that look bold on desktop but don't overwhelm mobile viewports. H1 can scale from 2rem on phone to 5rem on widescreen using a single clamp() value.
Grid gap & layout spacing
gap: clamp(1rem, 2vw, 2rem) on a CSS grid or flexbox container gives responsive gutters that tighten on small screens and expand on large ones — no media queries needed.
How it works
Linear interpolation
The generator calculates the line that passes through (minViewport, minSize) and (maxViewport, maxSize). The slope of this line becomes the vw coefficient; the y-intercept becomes the offset. The result is clamped to [min, max] at the boundaries.
SVG scaling graph
The graph plots the clamp curve — flat at min, linear in the fluid zone, flat at max — with your viewport breakpoints marked as vertical lines. It updates live as you type so you can see the shape of your scaling immediately.
Viewport audit table
The table computes the clamped value at 8 standard device widths (320px to 1920px). Each row shows whether the value is in the fluid range or clamped at min/max, so you can verify the result before shipping.
Four output formats
The generator outputs four immediately usable formats: plain clamp() value for copy-paste, full CSS property declaration, a CSS custom property definition with usage example, and a Tailwind CSS arbitrary value for JIT mode.
Related tools
Frequently asked questions
Quick answers about this free online tool.
