This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2020.
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.
width: max(20vw, 400px);
width: max(20vw, 100px);
width: max(5vw, 100px);
<section class="default-example" id="default-example">
<div class="transition-all" id="example-element">
<img
alt="Firefox logo"
class="logo"
src="/shared-assets/images/examples/firefox-logo.svg" />
</div>
</section>
In the first example shown above, the width will be at least 400px, but will be wider if the viewport is more than 2000px wide (in which case 1vw would be 20px, so 20vw would be 400px). This technique uses an absolute unit to specify a fixed minimum value for the property, and a relative unit to allow the value to grow to suit larger viewports.
max(1, 2, 3) max(1px, 2px, 3px)
The max() function takes one or more comma-separated expressions as its parameter, with the largest (most positive) expression value used as the value of the property to which it is assigned.
The expressions can be math expressions (using arithmetic operators), literal values, or other expressions, such as attr(), that evaluate to a valid argument type (like <length>), or nested min() and max() functions.
You can use different units for each value in your expression. You may also use parentheses to establish computation order when needed.
auto had been specified.min() and other max() functions as expression values. The expressions are full math expressions, so you can use direct addition, subtraction, multiplication and division without using the calc() function itself.min() and max() values, or use max() within a clamp() or calc() function.<max()> =
max( <calc-sum># )
<calc-sum> =
<calc-product> [ [ '+' | '-' ] <calc-product> ]*
<calc-product> =
<calc-value> [ [ '*' | / ] <calc-value> ]*
<calc-value> =
<number> |
<dimension> |
<percentage> |
<calc-keyword> |
( <calc-sum> )
<calc-keyword> =
e |
pi |
infinity |
-infinity |
NaN
When max() is used for controlling text size, make sure the text is always large enough to read. A suggestion is to use the min() function nested within a max() that has as its second value a relative length unit that is always large enough to read. For example:
small {
font-size: max(min(0.5vw, 0.5em), 1rem);
}
This ensures a minimum size of 1rem, with a text size that scales if the page is zoomed.
Another use case for max() is to allow a font size to grow while ensuring it is at least a minimum size, enabling responsive font sizes while ensuring legibility.
Let's look at some CSS:
h1 {
font-size: 2rem;
}
h1.responsive {
font-size: max(4vw, 2em, 2rem);
}
The font-size will at minimum be 2rems, or twice the default size of font for the page. This ensures that it is legible and accessible.
<h1>This text is always legible, but doesn't change size</h1> <h1 class="responsive"> This text is always legible, and is responsive, to a point </h1>
Think of the max() function as finding the minimum value allowed for a property.
| Specification |
|---|
| CSS Values and Units Module Level 4> # calc-notation> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
max |
79 | 79 | 75 | 66 | 11.1 | 79 | 79 | 57 | 11.3 | 12.0 | 79 | 11.3 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/CSS/max