minmax() CSS Function
The minmax() function sets a size range for a grid track: at least the minimum and at most the maximum, such as minmax(200px, 1fr).
Description
The minmax() CSS function defines a size range for a grid track: the track will be at least the minimum and at most the maximum. It is used in grid-template-columns, grid-template-rows, grid-auto-columns and grid-auto-rows, and is one of the key tools for building flexible, responsive grids.
Both arguments can be lengths, percentages, or the keywords min-content, max-content and auto. The maximum can also be a flexible fr value, but the minimum cannot. If the maximum is smaller than the minimum, the maximum is ignored. The most famous pattern combines minmax() with repeat() and auto-fit or auto-fill to create a grid that adds or removes columns automatically as space allows, without any media queries.
/* Responsive card grid: columns at least 200px, sharing extra space */
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 1rem;
}
/* Rows at least 100px tall but growing with their content */
.gallery {
grid-auto-rows: minmax(100px, auto);
}
/* Prevent a 1fr column from overflowing with long content */
.main {
grid-template-columns: minmax(0, 1fr) 300px;
}
Interactive Demo
Syntax
minmax() = minmax( [ <length-percentage> | min-content | max-content | auto ],
[ <length-percentage> | <flex> | min-content | max-content | auto ] )
Values
- minThe minimum size of the track: a <length-percentage>, min-content, max-content or auto. A <flex> (fr) value is not allowed here.
- maxThe maximum size of the track: a <length-percentage>, a <flex> value such as 1fr, min-content, max-content or auto. If it is smaller than min, it is ignored.
Example
Browser Support
The following information will show you the current browser support for the CSS minmax() function. Hover over a browser icon to see the version that first introduced support for this CSS function.
Desktop





Tablets & Mobile





