</> ConvertAtlas Developer Tools
Level 3 · Advanced — Modern CSS Lesson 31 Advanced 13 min

Modern Responsive Sizing With clamp, min and max

Fluid typography and spacing without breakpoints using clamp(), min() and max().

Breakpoints create sudden jumps. Modern CSS math functions — <code>clamp()</code>, <code>min()</code> and <code>max()</code> — let sizes flow smoothly between limits, so designs scale continuously with no jarring steps and far fewer media queries.

min() and max()

<code>min(a, b)</code> returns the smaller value; <code>max(a, b)</code> the larger. The classic use: <code>width: min(100%, 800px)</code> means "100% on small screens, but never wider than 800px" — a fluid container in one line.

HTML
<div class="box">width: min(100%, 400px)</div>
CSS
.box{width:min(100%,400px);background:#2563eb;color:#fff;padding:16px;border-radius:8px}
Result
Fluid up to 400px, then capped.

clamp(): the fluid powerhouse

<code>clamp(min, preferred, max)</code> gives a value that scales with the preferred (usually viewport-relative) value but never below min or above max. It is the single best tool for fluid typography.

HTML
<h1 class="t">Fluid heading</h1><p class="p">Body that scales gently.</p>
CSS
.t{font-size:clamp(1.6rem,5vw,3rem);margin:0 0 8px}
.p{font-size:clamp(1rem,2.5vw,1.25rem);color:#475569}
Result
Resize the preview — type scales smoothly between limits.

A fluid type scale

Define your headings and body once with clamp() and they all scale together across every screen — no breakpoints, no font-size media queries. Pair this with fluid spacing (e.g. <code>padding: clamp(1rem, 4vw, 3rem)</code>) for sections that breathe on large screens and stay tight on phones.

Fluid gaps and spacing

css
.section {
  padding-block: clamp(2rem, 6vw, 6rem);
}
.grid {
  gap: clamp(1rem, 3vw, 2rem);
}
Common mistake
Don't
h1 { font-size: 5vw; }
Do
h1 { font-size: clamp(1.6rem, 5vw, 3rem); }

Using a raw viewport unit for font size, which becomes unreadably small on phones or huge on monitors. Always wrap it in clamp() with sensible min and max.

Best practice

Build a fluid type and spacing scale with clamp() so the design adapts continuously. Keep media queries for structural changes (e.g. columns), not for resizing text.

Try it yourself

Make a heading use clamp(1.6rem, 5vw, 3rem) and a section use padding-block: clamp(2rem, 6vw, 6rem). Resize the preview and watch both scale smoothly with no breakpoints.

Quick quiz

1. width: min(100%, 800px) means…

2. clamp(1rem, 4vw, 2rem) does what?

3. Why wrap viewport units in clamp() for fonts?

Key takeaways
  • min()/max() cap or floor a value — min(100%, 800px) is a fluid container.
  • clamp(min, preferred, max) is the best tool for fluid typography.
  • Build a fluid type and spacing scale to avoid font-size breakpoints.
  • Keep media queries for structural changes, not resizing text.