There was a scripting error on this page. While it is being addressed by site editors, you can view partial content below.
The minmax
()
CSS function defines a size range greater than or equal to min and less than or equal to max. If max < min, then max is ignored and minmax(min,max)
is treated as min. As a maximum, a <flex>
value sets the flex factor of a grid track; it is invalid as a minimum.
Syntax
/* <inflexible-breadth>, <track-breadth> 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) /* <fixed-breadth>, <track-breadth> values */ minmax(200px, 1fr) minmax(30%, 300px) minmax(400px, 50%) minmax(50%, min-content) minmax(300px, max-content) minmax(200px, auto) /* <inflexible-breadth>, <fixed-breadth> values */ minmax(400px, 50%) minmax(30%, 300px) minmax(min-content, 200px) minmax(max-content, 200px) minmax(auto, 300px)
Values
- <length>
- A non-negative length.
- <percentage>
- A non-negative percentage relative to the inline size of the grid container in column grid tracks, and the block size of the grid container in row grid tracks. If the size of the grid container depends on the size of its tracks, then the
<percentage>
must be treated asauto
. The UA may adjust the intrinsic size contributions of the track to the size of the grid container and increase the final size of the track by the minimum amount that would result in honoring the percentage. - <flex>
- A non-negative dimension with the unit
fr
specifying the track’s flex factor. Each<flex>
-sized track takes a share of the remaining space in proportion to its flex factor. - max-content
- Represents the largest max-content contribution of the grid items occupying the grid track.
- min-content
- Represents the largest min-content contribution of the grid items occupying the grid track.
- auto
- As a maximum, identical to
max-content
. As a minimum it represents the largest minimum size (as specified bymin-width
/min-height
) of the grid items occupying the grid track.
Formal syntax
{{ csssyntax }}
Example
CSS content
#container { display: grid; grid-template-columns: minmax(max-content, 300px) minmax(200px, 1fr) 150px; grid-gap: 5px; box-sizing: border-box; height: 200px; width: 100%; background-color: #8cffa0; padding: 10px; } #container > div { background-color: #8ca0ff; padding: 5px; }
HTML content
<div id="container"> <div> Item as wide as the content,<br/> but at most 300 pixels. </div> <div> Item with flexible width but a minimum of 200 pixels. </div> <div> Inflexible item of 150 pixels width. </div> </div>
Result
Specifications
Specification | Status | Comment |
---|---|---|
CSS Grid Layout The definition of 'minmax()' in that specification. |
Candidate Recommendation | Initial definition |
Browser compatibility
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 57.0[1] | No support[3] | 52.0 (52.0)[2] | No support[3] | 44[4] | 10.1 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | No support | 52.0 (52.0)[2] | No support[3] | No support | 10.3 |
[1] Implemented behind the experimental Web Platform features flag in chrome://flags
since Chrome 29.0.
[2] Implemented behind the preference layout.css.grid.enabled
since Gecko 40.0 (Firefox 40.0 / Thunderbird 40.0 / SeaMonkey 2.37), defaulting to false
. Since Gecko 52.0 (Firefox 52.0 / Thunderbird 52.0 / SeaMonkey 2.49) the preference is enabled by default.
[3] Internet Explorer and Edge implement an older version of the specification, which doesn't define this.
[4] Implemented behind the Enable experimental Web Platform features flag in chrome://flags
since Opera 28.0.
See also
- Grid Layout Guide: Basic concepts of grid layout - track sizing with minmax()
- Video tutorial: Introducing minmax()