{{CSSRef}}{{SeeCompatTable}}
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 {{cssxref("<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)
Formal syntax
{{csssyntax}}
Example
CSS content
#container { display: grid; grid-template-columns: minmax(max-content, 300px) minmax(200px, 1fr) 150px; grid-gap: 5px; 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
{{EmbedLiveSample("Example", "100%", 200)}}
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName("CSS Grid", "#valdef-grid-template-columns-minmax", "minmax()")}} | {{Spec2("CSS Grid")}} | Initial definition |
Browser compatibility
{{CompatibilityTable}}
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}}[1] | {{CompatNo}} | {{CompatNo}}[2] | {{CompatNo}}[3] | {{CompatNo}}[1] | {{CompatUnknown}} |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatNo}}[1] | {{CompatNo}}[2] | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
[1] Implemented behind the experimental Web Platform features flag in chrome://flags
.
[2] Implemented behind the preference layout.css.grid.enabled
, defaulting to false
.