This family of math functions gives CSS real computing power: you can mix different units in arithmetic, pick the better of two candidate values, or confine a value to a safe range. The fluid font sizing in Section 4.5 is built precisely on these functions.
calc(): Mixing Units in Arithmetic
It supports the four basic arithmetic operations. Its greatest value lies in being able to mix different units — for instance, "viewport width minus a fixed pixel gutter", which is impossible to express with percentages or px alone.
Syntax detailSpaces are required around the plus and minus signs (calc(100% - 240px), not calc(100%-240px)), otherwise the expression is parsed as an invalid hyphenated value; spaces around multiplication and division are optional.
min() and max()
Both accept any number of arguments: min() applies the smallest value, max() the largest — essentially compressing the "take the smaller/larger one" logic that used to live in media queries into a single declaration.
/* container width: no more than 1200px, but leave 32px margin on small screens */.container {
width: min(1200px, 100% - 32px);
}
/* font size: never smaller than 14px */p { font-size: max(14px, 1vw); }
clamp(): Three-Value Clamping
clamp(min, preferred, max) is syntactic sugar for max(min, min(preferred, max)), and it is the most frequently used function in responsive typography:
h1 {
font-size: clamp(1.5rem, 4vw, 3rem);
}
Behavior of the three ranges
Viewport condition
Effective value
4vw evaluates to < 1.5rem
Takes the minimum, 1.5rem
1.5rem ≤ 4vw ≤ 3rem
Takes the preferred 4vw, following the viewport continuously
4vw evaluates to > 3rem
Takes the maximum, 3rem
Nesting Functions with Custom Properties
These functions can nest freely and read custom properties directly, composing complex adaptive logic:
Combining clamp() with Grid yields a layout whose "sidebar width glides with the viewport but has lower and upper limits", replacing what used to take two or three media queries:
The sidebar is never narrower than 200px (so the content is not crushed), never wider than 320px (to avoid taking up too much space on very wide screens), and in between it follows 20% of the viewport width smoothly.