CSS Portal

max() CSS Function

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
max()
CSS FunctionThis function is supported by all modern browsers.
Updated 31st December 2025

Description

The max() CSS function allows you to calculate the largest value from a list of two or more expressions. It is particularly useful when you want to define responsive sizes that adapt to different screen widths or conditions, ensuring a property never falls below a certain minimum. Unlike simple fixed values, max() can take relative units like percentages, viewport units, or other functions such as clamp() to create flexible layouts.

This function is often used with font-size, width, height, and margin to combine fixed and relative values. For example, you could ensure that a paragraph text never shrinks below 16px but can scale with the viewport width:

p {
  font-size: max(16px, 2vw);
}

Here, the browser will choose the larger value between 16px and 2vw, meaning on very small screens the font stays at 16px, but on larger screens it can grow proportionally.

Another practical use is for layout elements that should maintain a minimum size:

div.container {
  width: max(300px, 50%);
}

In this case, the container will be at least 300px wide, but can expand to 50% of its parent if that is larger.

The max() function can accept any number of comma-separated expressions and supports calculations using calc(). It helps create more robust, responsive designs without resorting to media queries for simple minimum thresholds.

It’s important to note that all units within max() must be compatible for meaningful comparisons; mixing incompatible units (like px and em in some contexts) may yield unexpected results.

Syntax

max() = max( value1, value2, ... )

Values

  • value1, value2, ...A list of comma-separated values - where the largest value is chosen. Required.

Example

<div class="container">
<div class="responsive-card">
<h2>Dynamic Scaling</h2>
<p>This card uses the max() function for its width.</p>
</div>
</div>
.container {
width: 100%;
padding: 20px;
background-color: #f0f0f0;
}

.responsive-card {
/* The width will never be smaller than 300px */
/* If 50% of the screen is more than 300px, it will take up 50% */
width: max(300px, 50%);

background-color: #007bff;
color: white;
padding: 20px;
border-radius: 8px;
margin: 0 auto;
text-align: center;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS max() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee