CSS minmax() Function
Example
Set the length/width range of an element:
#container
{
display:
grid
;
grid-template-columns:
minmax
(
max-content
,
300
px
)
minmax
(
200
px
,
1
fr
)
150
px
;
grid-gap:
5
px
;
box-sizing:
border-box
;
height:
200
px
;
width:
100
%
;
background-color:
#8cffa0
;
padding:
10
px
;
}
#container
div
{
background-color:
#8ca0ff
;
padding:
5
px
;
}
Try it »
Definition and usage
The minmax() function defines a closed interval of a length range; it works with CSS Grid Layout.
Supported version: CSS3
Browser support
The numbers in the table indicate the first browser version that supports the function.
| function | |||||
|---|---|---|---|---|---|
| var() | 57.0 | 16.0 | 76.0 | 10.1 | 44.0 |
CSS Syntax
/* , values */
minmax(200px, 1fr)
minmax(400px, 50%)
minmax(30%, 300px)
minmax(100px, max-content)
minmax(min-content, 400px)
minmax(max-content, auto)
minmax(auto, 300px)
minmax(min-content, auto)
/* , values */
minmax(200px, 1fr)
minmax(30%, 300px)
minmax(400px, 50%)
minmax(50%, min-content)
minmax(300px, max-content)
minmax(200px, auto)
/* , values */
minmax(400px, 50%)
minmax(30%, 300px)
minmax(min-content, 200px)
minmax(max-content, 200px)
minmax(auto, 300px)
| Value | Description |
|---|---|
| length | A non-negative length. |
| percentage | A non-negative percentage relative to the inline size of the grid container for column tracks and the block size for row tracks. If the grid container's size depends on its track sizes, the percentage must be treated as auto. A user-agent can adjust the track's intrinsic size contribution to the grid container, increasing the track's final size to the minimum amount that respects the percentage. |
| flex | A non-negative size with the fr unit specifies the track's flex factor. Any track sized with flex distributes the remaining space proportionally according to its flex factor. |
| max-content | Indicates that the grid track length adapts to the largest cell of its content. |
| min-content | Indicates that the grid track length adapts to the smallest cell of its content. |
| * auto* | As a maximum, it is equivalent to max-content. As a minimum, it represents the largest of the minimum sizes of the grid items occupying the grid track (as specified by min-width/min-height). |
CSS Functions