min(), max(), and clamp()
The min() and max() CSS functions return the minimum or maximum of the arguments, while clamp() clamps a value to a given range.
Overview
The min() and max() CSS functions return the minimum or maximum of the arguments, while clamp() clamps a value to a given range.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 79 | 79 | 75 | 13.1 | 79 | 13.4 | |
| Other | ||||||
| The max() CSS function lets you set the largest (most positive) value from a list of comma-separated expressions as the value of a CSS property value. The max() function can be used anywhere a <length>, <frequency>, angle, <time>, <percentage>, <number>, or <integer> is allowed. | 79 | 79 | 75 | 11.1 | 79 | 11.3 |
| The min() CSS function lets you set the smallest (most negative) value from a list of comma-separated expressions as the value of a CSS property value. The min() function can be used anywhere a <length>, <frequency>, angle, <time>, <percentage>, <number>, or <integer> is allowed. | 79 | 79 | 75 | 11.1 | 79 | 11.3 |
Syntax
.container {
/* Limit maximum width to 1200px */
width: min(100% - 2rem, 1200px);
}
.heading {
/* Fluid font size (range of 24px to 48px) */
font-size: clamp(1.5rem, 4vw, 3rem);
}
.card {
/* Ensure a minimum width of 300px */
width: max(300px, 30vw);
} Live demo
Use cases
Using min(), max(), and clamp()
The min() and max() CSS functions return the minimum or maximum of the arguments, while clamp() clamps a value to a given range.
Cautions
- May not be supported in older browsers.
Accessibility
- Make sure visual changes are conveyed appropriately to assistive technology.
Related links
Powered by web-features