CSS Reference ยท Functions
The max() function
Reference for the CSS max() function: how it picks the largest of several values, why it works as a minimum size, with live examples and usage notes.
The max() function takes a comma-separated list of values and resolves to the largest. It can compare different units, because the choice is made when the page is laid out.
Used on a size, max() acts as a minimum: the result is never smaller than any of the arguments.
CSS
.button { padding-inline: max(1rem, 3vw); }
Try it
Syntax
CSS
max( <calc-sum>#{2,} ) max(2rem, 5vw, 24px)
Syntax and arguments
| Part | Description |
|---|---|
| Arguments | Comma-separated values or arithmetic expressions of compatible types. |
| Arithmetic | + - * / work inside arguments without calc(); whitespace around + and - is required. |
| Result | The largest argument after resolution. |
Usage notes
max()= lower bound. Cap withmin(); bound both ways withclamp().- Safe areas:
padding-left: max(1rem, env(safe-area-inset-left))keeps at least 1rem but grows on notched devices. Seeenv(). - Readable text sizes:
max(16px, 1vw)stops text from getting smaller than a readable size on narrow screens. - Don't mix incompatible types (like a length and a time); the declaration is invalid.
- Nested use:
max(10px, min(5vw, 40px))works, thoughclamp()is clearer for that. - Prefer
min-widthand similar properties when you only need a floor on one property;max()is for computed combinations and for properties that have no min/max pair, likepaddingorgap.
Browser support
Supported in all current major browsers.
Related
min(),clamp(),calc()env()- Lesson: Math functions