The CSS clamp generator on this page turns four simple numbers — a minimum size, a maximum size, and the viewport range you want them tied to — into a single, production-ready clamp() declaration you can paste straight into your stylesheet. No more writing five separate media queries just to get a heading that scales smoothly from a phone to a widescreen monitor.
It does the linear-interpolation arithmetic for you, and it shows the computed size at six viewport widths so you can check the result before you paste it.
What This CSS Clamp Generator Does
Modern CSS gives us a function called clamp(MIN, PREFERRED, MAX) that lets a value — most often a font-size, but it works equally well for padding, margin, gap, or width — grow and shrink fluidly with the viewport, while never dropping below a floor or exceeding a ceiling. Instead of you working out the slope-intercept form of that "preferred" middle value by hand, this generator does it instantly: type in your smallest size, your largest size, and the two viewport widths those sizes should apply at, and it outputs the exact clamp() string, ready to copy.
It also renders a live preview table so you can see, in real numbers, what the computed size will be at six common screen widths — 320px and 375px (phones), 768px (a tablet), 1024px, 1440px, and 1920px (a large desktop) — so you're not just trusting the formula blindly.
How to Use the CSS Clamp Generator
- Set your minimum size. This is the smallest the element should ever render, in
remunits (e.g.1remfor body text, or1.5remfor a small heading). - Set your maximum size. This is the largest the element should render on a big screen, again in
rem. - Set the min and max viewport widths in pixels — the screen width at which the min size should apply, and the width at which the max size should apply.
- Click "Generate clamp()". The tool computes the slope and intercept of the linear ramp between those two points and assembles the full three-part
clamp()value. - Copy the output directly into your CSS — for example, as the value of
font-sizeon anh1, orpaddingon a section. - Check the live preview rows to confirm the computed size at 320px, 375px, 768px, 1024px, 1440px and 1920px looks right for your design.
The Formula — How clamp() Fluid Scaling Is Calculated
A fluid clamp() value has three parts: clamp(MIN, PREFERRED, MAX). The browser evaluates PREFERRED continuously and then clamps that number so it never goes below MIN or above MAX. The trick is building PREFERRED as a linear equation of the form A*vw + B, where A is a slope expressed in viewport-width units and B is a fixed offset in rem.
To find that slope and offset, treat it as two points on a line: at the minimum viewport width the value should equal the minimum size, and at the maximum viewport width it should equal the maximum size. The tool first converts both sizes to pixels (rem × root font size), then computes slope = (maxPx - minPx) / (maxVw - minVw), which is pixels of growth per pixel of viewport. Multiplying by 100 gives the vw coefficient, because 1vw is 1% of the viewport width.
The intercept is minPx - slope × minVw, divided by the root font size to express it in rem. With the defaults (1rem to 2.5rem between 400px and 1400px, 16px root) the sizes are 16px and 40px, the slope is 24 / 1000 = 0.024, so the vw coefficient is 2.4 and the intercept is 16 - 0.024 × 400 = 6.4px = 0.4rem. The tool outputs clamp(1rem, 0.4rem + 2.4vw, 2.5rem). Check: at 400px that is 6.4 + 9.6 = 16px, and at 1400px it is 6.4 + 33.6 = 40px. For the authoritative reference on how browsers evaluate this function, see the MDN documentation on clamp().
Why Fluid Typography Beats Fixed Breakpoints
Traditional responsive type relies on a handful of media-query "jumps" — say, 16px on mobile, 20px on tablet, 24px on desktop. The problem is the size snaps abruptly at each breakpoint instead of growing smoothly, and it does nothing useful for the (very common) viewport widths that sit between your breakpoints, like a foldable phone unfolded to 700px or a small laptop at 1152px. A clamp()-based value scales continuously across every width in between, so the type always looks proportionate to the screen it's on, and you write one line of CSS instead of four or five media queries per element.
This matters even more once you're maintaining a design system with dozens of type sizes — headings, subheadings, body copy, captions, button labels. Multiply five breakpoints by a dozen text styles and you're maintaining sixty media-query overrides. Multiply one clamp() line by a dozen text styles and you're maintaining twelve lines, full stop.
Common Use Cases Beyond Font Size
clamp() isn't limited to font-size. It works on any length-valued CSS property, which opens up a few patterns worth knowing:
- Fluid section padding — so a hero section has generous 96px padding on a widescreen monitor but tightens to 24px on a phone without a dozen media queries.
- Fluid gap in a CSS Grid or Flexbox layout — card grids that need a bit more breathing room at large sizes and a tighter gap on mobile.
- Fluid max-width on a content column — letting a text block widen gracefully on large screens while staying readable on small ones.
- Fluid border-radius or icon sizing — subtle, but it keeps small UI details visually consistent in proportion to the rest of the fluid layout.
Browser Support and Fallbacks
clamp() has been available across major browsers since July 2020, according to MDN's browser compatibility data, so in practice you rarely need a fallback for modern projects. If you must support a genuinely ancient browser, declare a plain fixed-size font-size rule first and then the clamp() version immediately after it in the same rule block — browsers that don't understand clamp() will simply ignore that second declaration and keep the fixed fallback, while modern browsers will use the fluid one, since the last valid declaration wins.
Building a Fluid Type Scale With Multiple clamp() Values
Most real projects don't need just one fluid size — they need a whole scale: a small caption size, a body size, a subheading, an H2, an H1, and maybe a large display heading for a hero section. A common pattern is to run this generator once per step in that scale, keeping the min and max viewport widths consistent across every step (say, 400px to 1400px, matching the defaults above) while varying only the min and max sizes per step.
That consistency matters more than it might seem: if every size in your scale ramps up across the exact same viewport range, the whole page scales in visual harmony — a heading and the body text beneath it grow at proportional rates rather than one snapping ahead of the other at a different width. A simple way to organise this is a small table of "min rem / max rem" pairs, generating every clamp() value from the same two shared viewport anchors, which is the workflow this tool supports.
It's also worth deciding, project by project, whether your min and max viewport anchors should track actual device breakpoints or your content's own natural constraints. Some teams anchor the minimum to their smallest supported phone (often 320–360px) and the maximum to a "typical" desktop content width (1200–1440px) rather than the full width of a 4K monitor, since text rarely needs to keep growing past a certain absolute size just because the window got wider — very large body text on an ultra-wide monitor usually looks worse, not better.
Testing Your clamp() Value in the Real Browser
Once you've copied a generated value into your stylesheet, don't just trust the math — open your browser's responsive design mode and physically drag the viewport width slider from your smallest supported width up to your largest.
Watch specifically for two failure modes: text that clips or wraps awkwardly at your minimum width (meaning your min size might still be a touch too large for that content), and text that looks disproportionately huge relative to surrounding fixed-size elements at your maximum width (meaning your max size may need trimming, or the surrounding elements should be fluid too). It only takes a few seconds per element, and it catches the kind of subtle sizing mismatch that's easy to miss when you're only looking at the numbers this calculator outputs rather than the rendered page itself.
How to Read the Result
- The clamp() value is ready to paste. The first part is your minimum, the last is your maximum, and the middle is the rem offset plus the vw slope.
- Slope is the vw coefficient: how many percent of the viewport width are added to the size. A bigger number means a steeper ramp.
- Intercept is the fixed rem part of the preferred value. It can be negative on a steep ramp that starts from a small size (such as 1.5rem to 6rem between 375px and 1440px). The generator then writes the vw term first, for example
6.7606vw - 0.0845rem, which is valid CSS you can paste as it is. - Size @ 375px and @ 1920px are the computed sizes at a typical phone and a large desktop, already limited by the min and max. The live preview shows six widths.
Four starting points, all with a 16px root:
| Use | Input | Output | Size @ 375px | Size @ 1920px |
|---|---|---|---|---|
| Default | 1rem to 2.5rem, 400px to 1400px | clamp(1rem, 0.4rem + 2.4vw, 2.5rem) | 16px | 40px |
| Body text | 1rem to 1.125rem, 320px to 1200px | clamp(1rem, 0.9545rem + 0.2273vw, 1.125rem) | 16px | 18px |
| Hero heading | 2rem to 4.5rem, 375px to 1440px | clamp(2rem, 1.1197rem + 3.7559vw, 4.5rem) | 32px | 72px |
| Section padding | 1.5rem to 3rem, 320px to 1200px | clamp(1.5rem, 0.9545rem + 2.7273vw, 3rem) | 26px | 48px |
What to Do Next
- Decide your two viewport anchors once and reuse them for every size in the scale.
- Generate each min and max pair, paste the values into your CSS custom properties, and apply them with
font-size: var(--step-1)or similar. - Drag your browser's responsive mode from 320px to 1920px and look for clipping at the small end and oversized text at the large end.
- Zoom to 200% and confirm the text still gets larger.
Arb Digital builds responsive websites with fluid type systems planned from the start. Explore our web design work or browse more free developer tools below.
Our Web Design Services All Free ToolsCommon Mistakes to Avoid With clamp()
- Mixing units carelessly. Keep your min/max sizes in
remand let the middle preferred value mixremandvw— mixing rawpxinto arem-based design system breaks accessibility scaling for users who increase their browser's default font size. - Picking a max viewport that's too small. If your max viewport is 900px, every screen above that (which is most desktops) will render at the exact same maximum size, defeating the "fluid" part of fluid typography on the screens where it matters most.
- Entering values the tool has to correct. If the max size is smaller than the min size the tool swaps them, and if the max viewport is not larger than the min viewport it adds 1px to it. Both usually mean a typo, so check the numbers you typed.
- Ignoring zoom. Text sized only in vw may not grow when a visitor zooms, because zooming narrows the viewport in CSS pixels. Keeping the rem part in the preferred value and in the min and max helps, but test at 200% zoom.
- Not testing the extremes. Always check the computed size at both your smallest supported phone and your largest supported monitor, not just the two viewport widths you typed in.
- Using clamp() for line-height inconsistently. If font-size scales fluidly but line-height is a fixed pixel value, text can look cramped or overly loose at the extremes — prefer unitless line-height values so they scale proportionally with the font-size automatically.
Related Free Tools From Arb Digital
Pair this generator with the CSS Specificity Calculator to debug why a style isn't applying, the CSS Minifier to ship a leaner stylesheet, the CSS Grid Generator and CSS Flexbox Generator for building the layouts your fluid type will live inside, and the Viewport Size Checker to see exactly how your live viewport compares to the breakpoints you're designing for. Browse everything in our free online tools hub.
Frequently Asked Questions
It takes three values — a minimum, a preferred value, and a maximum — and returns the preferred value unless it falls outside the minimum/maximum range, in which case it returns whichever limit was exceeded. This makes it ideal for fluid sizing that still has safe upper and lower bounds.
Yes. Any CSS property that accepts a length value — padding, margin, gap, width, max-width, border-radius, and more — can use clamp() the same way, which is why it's become a standard tool for fluid spacing systems, not just fluid type.
That middle "preferred" part is a linear formula, not a fixed number — it combines a fixed rem offset with a viewport-width-based component so the value changes continuously as the browser window resizes, rather than jumping at fixed breakpoints.
For most fluid sizing needs, no — clamp() replaces the media queries you'd otherwise write purely to step a size up or down. You'll still want media queries for structural layout changes, like switching from a single column to a multi-column grid.
It is supported in all current major browsers, including Chrome, Firefox, Safari, and Edge, and MDN lists it as available across browsers since July 2020. Very old browsers ignore it, so add a fixed fallback declaration first if you must support them.
Use 16px unless your project explicitly sets a different base font-size on the html element — 16px is the browser default and the standard assumption for converting rem-based sizes into the vw math clamp() uses internally.