Visual design · Step 2 · 6 min read
Fluid type with clamp()
A single type scale works for one viewport width. Fluid type, written with CSS clamp(), makes sizes grow smoothly between a minimum and a maximum — without media queries. This lesson shows the formula, the trade-offs and when Gale uses it.
Screens come in different sizes. Fluid typography with
clamp()handles that without media queries.
What you'll be able to do after reading:
- Explain what
clamp()does and write a valid fluid type declaration - Choose the right minimum and maximum values from Gale's scale
- Calculate or approximate the viewport-relative preferred value
- Decide when fluid type adds value and when a fixed scale is better
1. The problem: one size does not fit all screens
A fixed type scale — 11, 12, 14, 16, 20, 24, 32, 40 px — is designed for one context. At that size on a 1440 px desktop monitor, it reads well. On a 390 px phone, those same sizes may work. But on a 2 m control-room wall screen, 32 px is too small to read from across the room.
One solution is media queries: add a breakpoint rule at 1200 px and again at 320 px. That works, but it creates stepped jumps. The heading snaps from 24 px to 32 px at the breakpoint, with no transition between them.
Fluid type (tipografia fluida) is an alternative: a size that grows continuously from a minimum to a maximum as the viewport grows, without any explicit breakpoint.
2. The clamp() model: min, preferred, max
clamp(24px, 2.5vw, 40px) model for Gale Ops. Below 960 px the size is locked at 24 px (min). Between 960 px and 1600 px it scales with the viewport. Above 1600 px it locks at 40 px (max). No media queries needed. Diagram: Marcus Andrey, CC BY 4.0.The CSS clamp() function takes three values:
font-size: clamp(min, preferred, max);
- min — the smallest the size will go, even on the narrowest screen
- preferred — the value used when it falls within the min–max range; typically expressed in viewport units (
vw) so it grows with the screen - max — the largest the size will go, no matter how wide the screen
According to MDN, clamp(MIN, VAL, MAX) resolves as max(MIN, min(VAL, MAX)) — the preferred value, constrained between the minimum and maximum (MDN, clamp()). The function is widely supported across all major browsers (baseline since July 2020).
A concrete example for Gale Ops, where a main heading needs to read at both 1440 px and a 2 m wall screen:
.ops-heading {
font-size: clamp(20px, 2.5vw, 40px);
}
At 390 px, 2.5vw = 9.75 px, which is below the 20 px minimum — the size is clamped to 20 px.
At 800 px, 2.5vw = 20 px, which is exactly at the minimum — size is 20 px.
At 1440 px, 2.5vw = 36 px — in range, size is 36 px.
At 1600 px, 2.5vw = 40 px, which is exactly at the maximum — the size is 40 px.
3. Calculating the preferred value
The preferred value is the formula that scales the type between the minimum and maximum. The simplest form is Nvw — the size grows by N pixels for every 100 px of viewport width.
To find the right N:
- Pick your minimum size and the viewport width where it should start growing (e.g., 20 px at 800 px).
- Pick your maximum size and the viewport width where it should stop growing (e.g., 40 px at 1600 px).
- Calculate slope:
(40 - 20) / (1600 - 800) = 20 / 800 = 0.025, which is 2.5 vw. - The intercept:
20 - 0.025 × 800 = 20 - 20 = 0, so the full formula isclamp(20px, 2.5vw + 0px, 40px).
In practice, a pure vw value is a close enough approximation for most headings. The MDN accessibility note is worth keeping: when using clamp() for font sizes, make sure the maximum is at least twice the minimum so the text can scale to 200% when users zoom (MDN, clamp()).
If you want exact linear scaling, there are free calculators online (search "fluid type clamp calculator") that derive the formula from four input values: min size, max size, min viewport, max viewport.
4. When to use fluid type (and when not to)
Fluid type adds the most value when:
- The same component appears at very different viewport sizes (Gale Ops heading on a desktop vs a 70-inch wall screen).
- You want continuous scaling without media-query breakpoints.
- The product runs on a wide range of physical screen sizes, not just mobile vs desktop.
Fluid type adds less value or creates problems when:
- The scale is already fixed by the product's density requirements. Gale Console's 11 px column headers cannot shrink further; clamping them to
clamp(11px, 1.1vw, 11px)is pointless. - Components have specific dimensions that require specific text sizes. If a table cell is 32 px tall, the cell content must be 14 px regardless of the viewport.
- You need predictable layout — fluid type can cause text to wrap or overflow unexpectedly between breakpoints.
5. Gale Ops: the fluid type case
In Gale's three surfaces, only Gale Ops uses fluid type. The control-room view sits on monitors ranging from a 27-inch desk monitor to a 70-inch wall panel. The critical numbers — turbine availability, alarm counts, production figures — need to be readable from both close and far.
Gale Ops uses one fluid type rule for its main data readout:
.ops-readout {
font-size: clamp(14px, 1.5vw, 20px);
font-weight: 700;
font-variant-numeric: tabular-nums;
}
This matches Gale.md's declared value for Gale Ops: clamp(14px, 1.5vw, 20px). At 960 px, the size is 14.4 px (slightly above the 14 px minimum; no clamping). At 1440 px, it is 21.6 px (clamped to 20 px). The step between the minimum and maximum is approximately 1.43 — close to Gale's 1.25 scale step.
Gale Console and Gale Field keep fixed sizes. Their density requirements make fluid scaling impractical.
Fluid type is clear. Variable fonts go further: one file that covers all weights and sizes.
6. Common mistakes
- Using
clamp()with a preferred value so large that the min and max are both always hit — the type never actually fluids. - Forgetting the accessibility constraint: max should be ≥ 2× min so user zoom works correctly.
- Applying fluid type to labels and dense-data cells where layout depends on a stable size.
- Using
vwonly, with noclamp()minimum — text becomes unreadably small on narrow screens.
7. Vocabulary
| Term | Meaning |
|---|---|
| Fluid type | Type sizes that grow continuously with the viewport, using clamp(). No breakpoints needed. |
8. Try it
You need a browser and a text editor.
- Create a simple HTML page with one heading element.
- Set
font-size: clamp(1rem, 4vw, 3rem)on it. - Resize the browser window slowly from 320 px to 1400 px. Watch the heading size change.
- Now change the preferred value to
0.1vw. The size will pin to the minimum. Change it to20vw. The size will pin to the maximum. - Find the preferred value that makes the heading reach its maximum at exactly 1200 px:
max / 1200 × 100 = 3rem / 1200 × 100 ≈ 4vw(if you are working in px:48 / 1200 × 100 = 4vw).
You should now feel how the three values interact.
9. If you already practise
- Run an audit: search for
font-sizein your CSS. Count how many media-query overrides change font size at breakpoints. Each one is a candidate for aclamp()replacement. - Fluid type and fluid spacing often come together. The
clamp()model is the same:clamp(min, preferred, max).
Checklist
Learn more
- MDN, clamp() — syntax, examples and accessibility note
- MDN, CSS math functions —
min(),max()andclamp()together
Books, courses and videos to go deeper
- Web TypographyRichard RutterBook · Five Simple Steps, 2017 · — responsive typography chapter
- Modern Fluid Typography Using CSS ClampAdrian BeceSmashing Magazine, January 2022 · — practical guide with formulas and the math behind the preferred value (external site)
Related
Weight, tabular figures and fine details · Variable fonts and performance