CKTIS / CSS
minmax() — limits for a grid track
Give a grid row or column a minimum and a maximum, including a flexible maximum, without confusing track sizing with element sizing.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
minmax(min, max)
grid-template-columns: minmax(120px, 1fr) minmax(0, 1fr);minmax() defines a range for one grid track in properties such as grid-template-columns or grid-template-rows. It is not a general mathematical function for width. Its arguments describe track-sizing behavior: lengths, percentages, intrinsic sizes, or an automatic size; a flexible fraction is permitted only as the maximum.
minmax(120px, 1fr) preserves a 120-pixel floor and shares remaining space. In contrast, minmax(0, 1fr) permits the track to shrink below its content size; it does not itself wrap or clip overflowing content. A bare flexible fraction normally implies minmax(auto, 1fr), whose automatic minimum can keep a track larger.
If a fixed maximum is below the minimum, the minimum wins: minmax(140px, 80px) makes a 140-pixel track. minmax(1fr, 200px) is invalid because the minimum cannot be flexible. Track minima plus gaps may exceed the container. Percentages also depend on the container, with special intrinsic-sizing rules when its size is not definite.
Examples
const grid = document.createElement('div');
grid.style.cssText = 'display:grid;gap:20px;grid-template-columns:minmax(120px,1fr) minmax(0,1fr)';
grid.append(document.createElement('div'), document.createElement('div'));
document.body.append(grid);
for (const width of [400, 200, 100]) {
grid.style.width = width + 'px';
console.log(width + ':', getComputedStyle(grid).gridTemplateColumns);
}
grid.style.gridTemplateColumns = 'minmax(140px,80px)';
console.log('reversed bounds:', getComputedStyle(grid).gridTemplateColumns);
console.log('flexible minimum:', CSS.supports('grid-template-columns', 'minmax(1fr,200px)'));
grid.remove();Result
400: 190px 190px 200: 120px 60px 100: 120px 0px reversed bounds: 140px flexible minimum: false
Two empty tracks with a 20-pixel gap measure 190/190, 120/60, and 120/0 pixels in containers of 400, 200, and 100 pixels. The last grid necessarily overflows. The example also measures reversed fixed bounds and rejects a flexible minimum.