1fr vs minmax(0, 1fr) in CSS Grid

A bare 1fr Grid track has an automatic minimum. minmax(0, 1fr) replaces that lower bound with zero, allowing the track to fit the available space even when its contents would prefer a wider column.

The contents still need wrapping or scrolling rules. A zero minimum controls the track’s size; it does not make an oversized image or a preformatted line fit by itself.

Compare the overflowing and corrected layout
View code
HTML
<label><input id="fix" type="checkbox"> Apply minmax(0, 1fr)</label>
<div class="stage"><div class="layout"><aside>Sidebar</aside><main><pre>A_long_preformatted_line_that_should_scroll_inside_the_content_column_instead_of_widening_the_layout</pre></main></div></div>
<p class="note">Without the fix, scroll the outer frame. With the fix, scroll the code inside its column.</p>
CSS
button, select { padding: .35rem .6rem; border: 1px solid var(--clg); background: var(--cw); color: var(--cb); }
input[type="range"] { width: min(100%, 18rem); vertical-align: middle; }
h2, h3 { font-size: 1rem; }
.note { color: var(--clg); }

.stage { overflow: auto; border: 1px solid var(--clg); margin-top: 1rem; }
.layout { gap: .75rem; padding: .75rem; }
aside { padding: .5rem; background: var(--cg); }
main { border: 1px solid var(--cl); }
pre { overflow-x: auto; margin: 0; padding: 1rem; }
.layout { display: grid; grid-template-columns: 5rem 1fr; }
.layout.fixed { grid-template-columns: 5rem minmax(0, 1fr); }
JavaScript
document.querySelector('#fix').addEventListener('change', event => {
  document.querySelector('.layout').classList.toggle('fixed', event.target.checked);
});

Use minmax(0, 1fr) for a shrinkable main column

A fixed sidebar beside an article can use this track definition:

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

.layout pre {
  overflow-x: auto;
}

The Grid track-sizing definition gives a flexible track written outside minmax() an automatic minimum. That means 16rem 1fr can preserve a content-influenced minimum in the second column.

Using zero states that this track may become narrower than that minimum. The scrolling rule then gives long code somewhere to go without requiring a wider article column.

The fractional maximum is only half the rule

The <flex> reference describes fr as a share of remaining space in the grid. It does not mean all intrinsic sizing constraints disappear.

A wide preformatted line can make those constraints visible:

<div class="layout">
  <aside>Article navigation</aside>
  <main>
    <pre>A_long_preformatted_line_without_normal_word_wrapping_opportunities</pre>
  </main>
</div>

Without an appropriate track minimum, the grid can grow wider than expected even if the code block itself has an overflow rule. The browser must first decide how much space the track receives.

That is why changing the scrolling child sometimes appears to do nothing. The restrictive sizing decision may belong to the track or one of its ancestors.

Distinguish the track from the grid item

A grid item can also have an automatic minimum width. An explicit item minimum is another way to remove a content-based constraint:

.layout > main {
  min-width: 0;
}

The min-width documentation explains the conditions behind that automatic value. The track minimum and the item minimum are related, but they apply to different parts of the layout.

Choose whether the minimum belongs on the grid track, the grid item, or both. If the track must fit available space, define that in the track; if an item must shrink in several layouts, give the item that permission too.

Equal columns can use the same minimum

Three equal flexible columns can be declared with an explicit zero minimum:

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

The columns can stay equal even when one card contains a particularly long value. The card still needs to handle the value itself, perhaps with wrapping or a scrollable inner region.

Plain repeat(3, 1fr) can be appropriate when its content-based minimum is desirable. Protecting a piece of content from becoming too narrow is sometimes the intended behaviour.

Start with one column on small screens

A zero minimum cannot make a fixed sidebar fit a viewport narrower than the sidebar. The earlier two-column rule needs a responsive choice too:

.page {
  display: grid;
  gap: 2rem;
}

@media (min-width: 60rem) {
  .page {
    grid-template-columns: 18rem minmax(0, 1fr);
  }
}

.page pre {
  overflow-x: auto;
}

The breakpoint is illustrative. Choose it from the space required by the actual navigation and article, rather than treating 60rem as a universal threshold.

The single-column base also keeps the fixed navigation width out of the narrow layout. On wider screens, the article gets a flexible track with an explicit minimum.

Test the content policy as well as the tracks

A useful comparison includes a wide table, a large image, and an unbroken filename. Each reveals a different question: whether the container can shrink, whether its child can fit, and what the reader can do with any remaining overflow.

Use a constrained image rule where appropriate, and give genuinely wide content a deliberate scrolling region. Avoid hiding the problem by clipping information the reader needs.

The Flexbox minimum-width issue has the same broad lesson: flexible sizing still has minimum constraints. In Grid, an explicit track minimum is often the clearest place to describe that choice.

For wide code examples, keep the page within the viewport and let the code block scroll. It is more specific than declaring that every Grid layout should always use the same zero minimum.