min() is a ceiling, max() is a floor, clamp() is a corridor: the mental models and worked examples for reaching for the right CSS function.
What is fluid typography?
Fluid typography makes font sizes grow and shrink smoothly with the viewport instead of jumping between fixed sizes at breakpoints. In CSS, the clamp() function does the heavy lifting: clamp(minimum, preferred, maximum) picks a preferred value that scales with the viewport, but never goes below the minimum or above the maximum.
How clamp() works
The preferred value is usually a calculation like 1.2rem + 2.5vw: a fixed base plus a viewport-relative term. At your minimum viewport width it resolves to your minimum size; at your maximum viewport it resolves to your maximum size. Everywhere in between, it interpolates linearly. This calculator derives the exact intercept and slope so the line passes through both of your endpoints.
Why a type scale beats a single size
- Headings and body text stay in visual proportion at every screen width, not just at breakpoints.
- A consistent ratio (like 1.333) gives your whole page a rhythm designers recognize instantly.
- One factor pair applied to every step means you tune the whole scale with two numbers.
Accessibility notes
- Use
rem units so text still respects the user's browser font-size setting.
- Keep body text between 16px and 19px equivalent at the small end of your range.
- Fluid type is not a substitute for responsive layout; it pairs with it.
Frequently asked questions
What is the CSS clamp() function?
clamp(min, val, max) resolves to val unless it is smaller than min or larger than max. For typography, val is usually a calc combining a fixed term and a vw term, which makes the size fluid between the two endpoints.
How do I convert px to rem in clamp()?
Divide by your root font size, almost always 16. So 24px becomes 1.5rem. This calculator outputs rem by default because rem respects the user's browser text-size preference, which matters for accessibility.
What viewport range should I use?
A common pair is 360px (small phones) to 1280px (laptops). Sizes below 360px are rare enough that the minimum bound handles them; sizes above 1280px are handled by the maximum bound, so giant monitors don't get giant text.
Which type scale ratio should I pick?
1.333 (perfect fourth) is the safest default: noticeable hierarchy without melodrama. Use 1.25 for dense, content-heavy UIs and 1.5 or 1.618 when you want editorial drama. This tool previews every step, so try ratios and watch the preview.
Does clamp() work in all browsers?
clamp() is supported in all modern browsers released since 2020 (Chrome 79+, Firefox 75+, Safari 13.1+, Edge 79+). For older browsers you can add a fixed-size fallback declaration before the clamp() line; browsers that understand clamp() will override it.
Can I use fluid type with Tailwind?
Yes. Paste this tool's Tailwind v3 config snippet into theme.extend.fontSize for utilities like text-step-3, or use the v4 @theme tokens in your CSS. Both export tabs generate the code from your current settings.
Guides
CSS clamp() for fluid navigation menu font size: one line holds nav links between 14px and 18px, fluid from 400px to 1200px, with a fluid gap to match.
CSS clamp() for fluid container max width replaces a ladder of media queries with one width line: a floor for small phones, a viewport-relative middle, and a ceiling that keeps lines readable.
CSS clamp() for fluid hero section height fixes the two classic hero failures: a fixed height that crowds desktop and a 100vh hero that swallows a phone screen. One min-height line, three values, no breakpoints.
One grid track that holds a sidebar between 220px and 360px, the vw trap that breaks sidebars, and the stacking fix for small screens.
One clamp() line holds hero and card images between a floor and a ceiling, with the container trap explained.
One clamp() line keeps card gutters tight on phones and generous on desktops, with separate row and column gaps.
Fixed pixel radii look tiny on desktop and chunky on phones. One clamp() line scales the corners between your tokens, with the percentage pitfall explained.
One clamp() line for button padding, one for the font size, and the em trick that keeps the two in proportion. The touch target floor and a worked recipe.
The going advice says to use clamp() with dvw instead of vw for mobile fluid layouts. The width math says otherwise; the height math is where the swap earns its keep.
Put em in the middle slot and the whole clamp rides on the component's font size. When it helps, when rem is better, and the nesting trap.
Let the ratio pick the sizes and clamp() make them fluid. The modular scale math, the 2-ratio trick behind Utopia's generator, and real scale output values.
Both directions nest fine, but each has a natural job. calc() inside clamp() for mixed-unit preferred values, clamp() inside calc() when you subtract a fixed offset from a fluid value.
One clamp() line replaces three stepped media queries for sizes and spacing. The linear-interpolation formula and the layout decisions you should not touch.
Two divisions tell you exactly which viewports ever see the fluid middle of your clamp(). Worked out on three real snippets, including the popular body-text one.
The short answer is yes, in both directions. Storing the whole clamp() in a variable is how I run type scales now. There is one catch, and it is about animation.
One scale, three headings, no breakpoints. The clamp values and the ratio that keep H1, H2, and H3 in proportion.
The preferred value in clamp() is the equation of a line. Two endpoints, slope, intercept, worked through with real numbers, plus the thirty-second check that catches slips.
For years I nested calc() inside every clamp() out of habit. When the nesting is optional, when it is required, and the mistakes that silently break calc().
Viewport units do not know where your component lives. Container query units do. How to make clamp() type respond to the card instead of the screen.
When clamp earns its place on card widths, when auto-fit minmax wins, and the decision rules for picking between them.
Unitless line-height values cannot go inside clamp(). The em-based formula that can, a worked example, and why I rarely bother.
Min and max should be rem. The preferred value is where the argument lives. Here is the zoom math, the one place px is fine, and the 2.5x ceiling rule.
Pure vw ignores browser zoom, failing WCAG 1.4.4. The rem + vw formula that keeps fluid type accessible, with the demo numbers.
Fluid section padding, card gutters, and grid gaps that scale with the viewport, plus the rule for which spacing stays fixed.
Two fallback approaches for clamp(): the static declaration above, and the @supports not block. Plus the IE11 edge case that breaks the fancy one.
How the browser resolves min, preferred, and max, with a worked fluid-type example and the rem accessibility rule.
When one line of clamp() replaces four breakpoints, and when media queries still win.