Favorites

minmax() CSS Function

minmax()
CSS FunctionThis function is supported by all modern browsers.
Updated 21st November 2026

The minmax() function sets a size range for a grid track: at least the minimum and at most the maximum, such as minmax(200px, 1fr).

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

Description

The minmax() CSS function defines a size range for a grid track: the track will be at least the minimum and at most the maximum. It is used in grid-template-columns, grid-template-rows, grid-auto-columns and grid-auto-rows, and is one of the key tools for building flexible, responsive grids.

Both arguments can be lengths, percentages, or the keywords min-content, max-content and auto. The maximum can also be a flexible fr value, but the minimum cannot. If the maximum is smaller than the minimum, the maximum is ignored. The most famous pattern combines minmax() with repeat() and auto-fit or auto-fill to create a grid that adds or removes columns automatically as space allows, without any media queries.

/* Responsive card grid: columns at least 200px, sharing extra space */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* Rows at least 100px tall but growing with their content */
.gallery {
  grid-auto-rows: minmax(100px, auto);
}

/* Prevent a 1fr column from overflowing with long content */
.main {
  grid-template-columns: minmax(0, 1fr) 300px;
}

Interactive Demo

Supercalifragilistic
Two
Three
Four
Five
Six
Demo Code
HTML Code
<div class="demo-element">
	<div>Supercalifragilistic</div>
	<div>Two</div>
	<div>Three</div>
	<div>Four</div>
	<div>Five</div>
	<div>Six</div>
</div>
CSS Code
.demo-element > div {
	padding: 8px;
	background: #4361ee;
	color: #fff;
	font-size: 13px;
}
.demo-element > div:nth-child(2n) {
	background: #f72585;
}
.demo-element {
	display: grid;
	width: 300px;
	gap: 6px;
	padding: 6px;
	box-sizing: border-box;
	background: #f4f4f4;
	outline: 1px dashed #b0b0b0;
	grid-template-columns: minmax(100px, 1fr) 1fr 1fr;
}

Syntax

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

Values

  • minThe minimum size of the track: a <length-percentage>, min-content, max-content or auto. A <flex> (fr) value is not allowed here.
  • maxThe maximum size of the track: a <length-percentage>, a <flex> value such as 1fr, min-content, max-content or auto. If it is smaller than min, it is ignored.

Example

<div class="wrap">
<h1>CSS minmax() examples</h1>
<div class="cards">
<div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><div>6</div>
</div>
<p class="note">repeat(auto-fit, minmax(150px, 1fr)). Drag the bottom-right corner, or resize the window, to see columns appear and disappear.</p>
</div>
/* Base demo layout */
* { box-sizing: border-box; }

body {
margin: 24px;
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial;
background: #f5f7fb;
color: #102a43;
}

.wrap {
max-width: 860px;
margin: 0 auto;
}

h1 {
font-size: 20px;
margin: 0 0 16px;
}

.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 16px;
}

.card {
background: #fff;
border-radius: 12px;
padding: 16px;
box-shadow: 0 6px 18px rgba(16, 42, 67, 0.08);
}

.label {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
font-size: 12px;
color: #486581;
margin-top: 10px;
word-break: break-word;
}

.note {
font-size: 13px;
color: #486581;
margin-top: 14px;
}

/* minmax() examples */
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 12px;
resize: horizontal;
overflow: auto;
padding: 12px;
border: 2px dashed #94a3b8;
border-radius: 10px;
min-width: 180px;
}

.cards div {
padding: 20px 12px;
border-radius: 8px;
background: #2563eb;
color: #fff;
font-weight: 600;
text-align: center;
}
Open in editor

Browser Support

The following information will show you the current browser support for the CSS minmax() function. Hover over a browser icon to see the version that first introduced support for this CSS function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.