Skip to tool
ecech.
💻 Developer & Code

Free CSS clamp Calculator for Fluid Typography That Still Respects Browser Zoom

Generate production-ready clamp() from two sizes and two viewports — with the rem term that stops your text ignoring browser zoom, which pure vw versions break.

px
px
px
px

The CSS






Size across the range

240px768px1920px

The quick brown fox

Common steps

Role Min Max clamp()
Advertisement

How the calculation works

clamp(MIN, PREFERRED, MAX) MIN 1.125rem the floor. Never smaller, however narrow the screen. PREFERRED 0.8333rem + 1.4583vw the slope. The rem part is what keeps zoom working. MAX 2rem the ceiling. Stops headings becoming billboards at 4K. One declaration replaces three media queries, and scales smoothly between them instead of jumping. A preferred value of pure vw — no rem term — looks identical and silently breaks browser zoom.

How to Use This Tool

clamp() takes three values: a floor, a preferred value, and a ceiling. Give it a size for your smallest viewport and a size for your largest, and it scales smoothly between them — replacing a stack of media queries with one line that never jumps.

The arithmetic

The preferred value is the straight line through your two points. The slope is (maxSize − minSize) ÷ (maxViewport − minViewport), expressed in vw by multiplying by 100. The intercept is what is left over at the minimum viewport, expressed in rem. For 18px at 320px growing to 32px at 1280px, the slope is 14 ÷ 960 = 1.4583vw and the intercept works out at 0.8333rem.

The accessibility problem almost every generator has

It is tempting to write the preferred value as pure vw, because the numbers are tidier. Do not. Viewport units do not respond to browser zoom or to a user's default font size. A heading sized entirely in vw stays exactly the same physical size when someone zooms to 200%, which is a failure of WCAG success criterion 1.4.4 (Resize Text).

The fix is the rem term in the preferred value. Because rem is relative to the root font size, the whole expression scales when the user changes their settings, while the vw part still does the fluid work. Keep the zoom-safe box ticked and the calculator always produces both terms. Untick it and you get the tidier version, plus a warning, because sometimes you genuinely do want a decorative element pinned to the viewport.

A user zooms the browser to 200%. What happens to the heading? Pure vw clamp(1.125rem, 2.5vw, 2rem) Heading Heading at 100% at 200% Identical. Zoom did nothing. With a rem term clamp(1.125rem, 0.83rem + 1.46vw, 2rem) Heading Heading at 100% at 200% Grows, as the user asked.
Both declarations look almost the same and behave identically until someone needs to zoom. That is precisely the population this matters most for.

Reading the chart

The chart plots the computed size at every viewport width. It is flat below your minimum, a straight diagonal through the middle, and flat again above your maximum. If the diagonal looks too steep, your two sizes are too far apart for the viewport range — text will change noticeably as someone resizes a window, which reads as instability rather than responsiveness.

It is not only for type

The same expression works for padding, gaps, border radii and container widths. Fluid spacing is arguably a bigger win than fluid type, because the alternative is redefining every gap at three breakpoints. Switch the values to your spacing scale and the output is identical in form.

Two practical cautions

Do not clamp everything. A page where every size is fluid has no rhythm, because nothing lines up with anything else at intermediate widths. Pick a few roles — body, one or two heading levels, section spacing — and leave the rest on a fixed scale.

And check the minimum against real content. A 320px viewport with a long unbroken word will still overflow no matter how small the clamp floor is; that is a wrapping problem, not a sizing one.

Advertisement

Frequently Asked Questions

How does clamp() work in CSS?
It takes three values — a minimum, a preferred value and a maximum — and returns the preferred value unless it falls outside the bounds, in which case it returns the nearest bound. Written as clamp(1.125rem, 0.83rem + 1.46vw, 2rem), the middle term grows with the viewport while the outer two stop it going too small or too large.
Why does my vw-based font size ignore browser zoom?
Because viewport units are relative to the viewport, not to the user's font settings, so they do not change when someone zooms or raises their default text size. A font size expressed purely in vw therefore stays the same physical size at 200% zoom, which fails WCAG success criterion 1.4.4. Including a rem term in the preferred value fixes it.
How do I calculate the slope and intercept myself?
The slope is the size difference divided by the viewport difference, multiplied by 100 to express it in vw. The intercept is the minimum size minus the slope multiplied by the minimum viewport, then divided by your root font size to express it in rem. For 18px at 320px to 32px at 1280px: slope = 14/960 × 100 = 1.4583vw, intercept = 0.8333rem.
Should I use rem or px in the clamp bounds?
rem, for anything involving text. The bounds in px would ignore a user who has raised their browser's default font size, which defeats the point of the rem term in the middle. For purely decorative dimensions that should not scale with text, px bounds are defensible.
Can I use clamp() for padding and margins?
Yes, and it is arguably more useful there than for type. Fluid spacing removes the need to redefine every gap at each breakpoint, and the calculation is identical — just enter your spacing values instead of font sizes. It works for gap, border-radius, width and any other length property.
What browser support does clamp() have?
It is supported in every current browser and has been since 2020, so for most projects no fallback is needed. If you must support something older, declare a plain fixed size on the line before the clamp declaration; browsers that do not understand clamp will ignore that line and keep the fixed value.
Why does my text change size so noticeably when I resize the window?
Your two sizes are probably too far apart for the viewport range, making the slope steep. Text that visibly grows as you drag a window edge reads as instability rather than responsiveness. Narrowing the gap between the minimum and maximum sizes, or widening the viewport range, both flatten it.

Related tools in Developer & Code

Browse all Developer & Code tools
A handwritten note reading ecech.com resting on the keyboard used to build the site.

Made by one person

ecech. is not a content farm. Every tool here is written and checked by hand, one at a time, by someone who wanted the tool to exist and could not find a version that showed its working.

No accounts and no sign-in, and nothing you type reaches a server — every calculation on this page runs inside your browser. The ads are served by Google and do set their own cookies, which is set out in full on the privacy page. More about the site.