Lesson 10 of 30
Scaling type or spacing across breakpoints used to mean a jumpy staircase of fixed values in media queries. clamp() replaces the staircase with one continuously fluid value that scales smoothly between a floor and a ceiling.
12 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
What is clamp(1rem, 4vw, 3rem) equivalent to, in terms of min()/max()?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
The old way to make a heading readable at both phone and desktop widths was a series of fixed font-size values, one per breakpoint, switched abruptly by media queries: 1.5rem up to 640px, 2rem up to 1024px, 2.5rem beyond that. It works, but it's a step function — the size jumps at each breakpoint boundary instead of changing smoothly, and every new screen size in between gets whichever value happened to be active, not a value actually tuned for it.
min(), max(), and clamp() are CSS functions that let a single value respond continuously to something like viewport width, no media query involved:
min(a, b) picks whichever of the two values is smaller at any given moment.max(a, b) picks whichever is larger.clamp(floor, preferred, ceiling) picks the preferred value, but never lets it go below floor or above ceiling. It's built from the other two: clamp(floor, preferred, ceiling) behaves the same as max(floor, min(preferred, ceiling)) — take the preferred value, cap it from above with min(), then cap it from below with max()./* Before: a jumpy staircase */
h1 {
font-size: 2rem;
}
@media (min-width: 640px) {
h1 { font-size: 3rem; }
}
@media (min-width: 1024px) {
h1 { font-size: 4rem; }
}
/* With clamp(): one continuous curve */
h1 {
font-size: clamp(2rem, 1rem + 4vw, 4rem);
}
The clamp() version never renders smaller than 2rem or larger than 4rem, and between those bounds it follows 1rem + 4vw — a value that grows continuously as the viewport widens, because vw is a percentage of viewport width. The heading scales smoothly at every width, not just the three the media-query version happened to define, and there's a single line of CSS to maintain instead of three.
clamp() is genuinely built from min() and max(), not just conceptually similar to them — clamp(floor, preferred, ceiling) is equivalent to max(floor, min(preferred, ceiling)). Understanding that composition makes it much easier to reason about what a given clamp() value will actually resolve to at any width.vw value alone is dangerous for font-size — text sized only in vw (no clamp() bounds) can shrink low enough at narrow widths to become unreadable, or grow large enough at wide widths to break layout, since it has no floor or ceiling. That's precisely the failure mode clamp() exists to prevent.clamp(1rem, 0.5rem + 2vw, 2.5rem) combining a fixed rem value with a viewport-relative vw value in the same expression is a normal, common pattern, not an edge case.min() and max() are broadly supported and safe to use directly. They're simple, well-established functions — the honest caveat is really about designing the values passed to clamp() sensibly (testing the actual range it produces across real viewport widths), not about browser support risk."How would you make a heading scale smoothly across screen sizes without writing multiple media queries?" tests whether a candidate can name clamp() specifically and explain why it's smooth — not just that it exists, but that it's max(floor, min(preferred, ceiling)) under the hood, which is the difference between having used it once and actually understanding it.