November 27, 2026 • By

CSS minmax() explained: how it works in grid

The short version

  • minmax(min, max) gives a grid track a size range: it can't get smaller than min or bigger than max. It only works in grid-template-columns, grid-template-rows, grid-auto-columns and grid-auto-rows.
  • Both arguments can be a length, a percentage, auto, min-content or max-content. A flex value like 1fr is allowed only as the max, and minmax(1fr, 300px) makes the browser drop the whole declaration.
  • If the max is smaller than the min, the max is ignored, so minmax(300px, 100px) is a 300px track.
  • A bare 1fr is short for minmax(auto, 1fr), so it can't shrink below its content. With a one-line code block, two 1fr columns came out 1037px and 187px on a 1280px screen. minmax(0, 1fr) kept them at 612px each.
  • repeat(auto-fit, minmax(300px, 1fr)) overflows on screens narrower than 300px plus padding. minmax(min(300px, 100%), 1fr) fixes that by letting the column shrink to the container's width.

minmax(min, max) gives a grid track a size range. The column (or row) can't get smaller than min and can't get bigger than max, and the browser picks a size in between based on the space it has and what's inside the track. You can only use it in grid track sizes: grid-template-columns, grid-template-rows, grid-auto-columns and grid-auto-rows.

.layout {
    display: grid;
    grid-template-columns: minmax(200px, 300px) 1fr;
    gap: 16px;
}

Here the first column is a sidebar that stays between 200px and 300px wide, and the second column takes whatever is left. On a 1280px screen with 20px of padding on each side, the sidebar is 300px and the main column gets the other 924px.

Below are the values minmax() accepts and the two rules that catch people out, followed by the places you'll use it most, like minmax(0, 1fr) and the responsive card grid. I rendered every example in Chromium at a few screen widths, and the numbers in this post come from those tests.

The values minmax() accepts

Both arguments can be a length (200px, 10rem), a percentage, or one of the keywords auto, min-content and max-content. The max can also be a flex value like 1fr. The min can't.

ValueAs min?As max?What it means
200px, 10remYesYesA fixed size
25%YesYesA share of the grid container's width (columns) or height (rows)
1frNoYesA share of the free space left in the grid
autoYesYesAs min: the largest minimum size of the items in the track. As max: the same as max-content, but the track can also stretch to fill the container
min-contentYesYesThe narrowest the content can get, with every possible line break taken
max-contentYesYesThe width the content wants with no line breaks

min-content and max-content are easiest to see together. minmax(min-content, max-content) on a column holding the text "one two three four five six seven" made the column 210px wide in a 1000px container, the width of the sentence on one line. In a 40px container the column stopped shrinking at 36px, the width of "seven", its longest word, and the text wrapped onto one line per word.

The two rules

If max is smaller than min, the max is ignored

minmax(300px, 100px) is valid CSS, but the browser treats it as 300px. The spec says the max "will be floored by the min", which means the min always wins. I tested it, and the column was 300px wide at every screen width.

fr can't be the min

fr means a share of the leftover space, and the browser only knows how much space is left over once it has worked out the minimums, so the spec only allows fr as a max. minmax(1fr, 300px) is invalid, and the browser drops the whole declaration. If you had an earlier grid-template-columns in the same rule, that one is used instead, and if not, the grid falls back to a single column.

repeat(auto-fit, minmax(300px, 1fr))

This is the line most people come to minmax() for:

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

Every column has to be at least 300px, and 1fr lets the columns share whatever space is left. auto-fit creates as many columns as fit at 300px, so in my test a 1280px screen got three columns of 403px and a phone got one, with no media queries.

I won't repeat the whole tutorial here. My CSS grid auto-fit and minmax() article builds a full layout with it and covers the difference between auto-fit and auto-fill.

The fix for narrow screens: min(300px, 100%)

minmax(300px, 1fr) has one problem. On a screen narrower than 300px plus your padding, the single column still has to be 300px, so it sticks out of its container.

With 20px of padding on each side, a 320px screen leaves a 280px container. The column stayed 300px and ran over the right padding to the edge of the screen. On a 300px screen the container was 260px, the column was still 300px and the page scrolled sideways.

Wrap the min in min():

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 16px;
}

min() returns the smaller of its two values. On any screen with room for a 300px column, that's 300px, so nothing changes. On a tiny screen, 100% of the container is smaller, so the column becomes exactly as wide as the container: 280px at 320px wide and 260px at 300px wide, with no sideways scroll. At 375px and 1280px the two versions gave identical columns.

What does minmax(0, 1fr) do?

minmax(0, 1fr) makes a column that takes its share of the free space and is allowed to shrink all the way to zero. That sounds the same as 1fr, and most of the time it is. The difference shows up when something inside the column is wider than the column wants to be.

A bare 1fr isn't really a minimum of zero. The spec says an fr value on its own "implies an automatic minimum", so 1fr is short for minmax(auto, 1fr). And auto as a min means the column can't get narrower than the largest minimum size of its items. For a grid item, that minimum is usually its content, such as a long word or a line of code that can't wrap.

Why 1fr overflows with long content

Take two 1fr columns where the first holds a one-line code block:

<div class="grid">
    <div>
        <pre>const result = await fetch('https://api.example.com/v1/some/really/long/endpoint/path', { method: 'POST' });</pre>
    </div>
    <div>short</div>
</div>
.grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

pre {
    overflow-x: auto;
}

You'd expect two equal columns. On a 1280px screen I got 1037px and 187px, because the first column wouldn't go narrower than the code. On a 375px screen it was worse: the columns were 1037px and 36px, and the page was 1108px wide.

The overflow-x: auto on the pre didn't help, because the grid item is the div around it, and that div still reports the code's width as its minimum.

Change the columns to minmax(0, 1fr):

.grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
}

Now the columns are 612px each at 1280px and 160px each at 375px, and the code block scrolls inside its column. Writing minmax(auto, 1fr) out in full gave me exactly the same widths as 1fr, which is what the spec says should happen.

Setting min-width: 0 on the grid items does the same job as minmax(0, 1fr), since it removes the content-based minimum that auto was reading. I got the same 612px and 160px columns with it.

Which one should you use?

Use minmax(0, 1fr) when you want columns that stay equal no matter what's in them, like a 12-column layout. The footer on this site is a grid with repeat(12, minmax(0, 1fr)). Tailwind's grid-cols-12 generates the same value, which is why Tailwind grids don't blow out on long content.

Keep plain 1fr when you'd rather the column grow than have its content overflow or scroll. A column of buttons or a form label is usually better wider than clipped.

minmax() for rows: minmax(100px, auto)

minmax() works on rows too. The common use is rows with a minimum height that still grow when the content needs more room:

.list {
    display: grid;
    grid-auto-rows: minmax(100px, auto);
    gap: 16px;
}

With three items, where the second has eight lines of text, the rows came out 100px, 144px and 100px. The short items got the 100px minimum and the tall one grew to fit. With a fixed grid-auto-rows: 100px instead, the tall item stayed 100px high and its text ran 44px out of the bottom, over the gap and into the next item.

grid-auto-rows sizes every row the grid creates, so you don't need to know how many rows there will be. If you do know, grid-template-rows: repeat(3, minmax(100px, auto)) gave me the same three rows.

Can I use minmax()?

Yes. MDN lists minmax() as available in every major browser since October 2017. min(), used in the narrow-screen fix above, has worked everywhere since 2020.

Sources

Frequently asked questions

What does minmax(0, 1fr) do?

It makes a column that takes its share of the free space and can shrink all the way to zero. A bare 1fr means minmax(auto, 1fr), so it can't get narrower than its content. minmax(0, 1fr) keeps columns equal even when one holds long content like a code block, which then scrolls inside its column.

Can fr be the minimum in minmax()?

No. fr is only allowed as the max. minmax(1fr, 300px) is invalid and the browser drops the whole declaration.

What happens if the max is smaller than the min?

The max is ignored and the track uses the min, so minmax(300px, 100px) is 300px.

How do I give grid rows a minimum height that still grows?

Use grid-auto-rows: minmax(100px, auto). Rows are at least 100px and grow to fit taller content.

Share this article

Hassan Aziz pointing up

Dude, you’re at the bottom of my landing page.

Just book a call already if you’re that interested.

You scrolled all the way here.

Book a free call on Calendly