minmax()
Quick Summary for minmax()
The minmax() CSS function defines a size range greater than or equal to min and less than or equal to max. It is used with CSS Grids.
Code Usage for minmax()
/* <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) 
More Details for minmax()

minmax()

The minmax() CSS function defines a size range greater than or equal to min and less than or equal to max. It is used with CSS Grids.

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) 

A function taking two parameters, min and max.

Each parameter can be a <length>, a <percentage>, a <flex> value, or one of the keyword values max-content, min-content, or auto.

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.

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 as auto. The user agent 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 by min-width/min-height) of the grid items occupying the grid track.

Formal syntax

minmax( [ <length> | <percentage> | min-content | max-content | auto ] , [ <length> | <percentage> | <flex> | min-content | max-content | auto ] )

CSS properties

minmax() function can be used within:

grid-template-columns grid-template-rows grid-auto-columns grid-auto-rows

Examples

CSS

#container {   display: grid;   grid-template-columns: minmax(min-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

<div id="container">   <div>     Item as wide as the content, 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
CSS Grid Layout Module Level 3 # valdef-grid-template-columns-minmax

See also

Grid Layout Guide: Basic concepts of grid layout - track sizing with minmax() CSS grids, logical values and writing modes Video tutorial: Introducing minmax() Select your preferred language English (US)EspañolFrançais日本語Русский中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
When i was a little kid, I was really scared of the dark. But then I came to understand, dark just means the absence of photons in the visible wavelength -- 400 to 700 nanometers. Then i thought, well, its really silly to be afraid of a lack of photons. Then i wasn't afraid of the dark anymore after that.
Elon Musk
Random CSS Property

align-tracks

Experimental: This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.
align-tracks css reference