CSS Grid min-width 0 fixes overflow when a grid item or grid track refuses to shrink because long text, media, URLs, cards, or content-based minimum sizes force the grid wider than its container.
CSS Grid Overflow Fix
Why does CSS Grid need min-width:0?
CSS Grid often needs min-width:0 because grid items can have a content-based minimum size. That means a grid column may look flexible on paper, but still refuse to shrink when the content inside it is long, unbroken, or naturally wide. The grid container may be responsive. The track may use 1fr. The page may have a safe wrapper. Still, one stubborn grid item can push the entire layout wider than the screen.
This is the grid version of a classic overflow trap. Developers see grid-template-columns: 1fr 1fr and expect both columns to share the available space. But 1fr does not always mean “ignore the content minimum.” If one grid item contains a long title, URL, code line, image, or nested card, the column can preserve more width than the parent has available. Adding min-width:0 to the grid item or using minmax(0, 1fr) on the track tells the grid that shrinking is allowed.
- CSS Grid
- min-width:0
- Grid overflow
- 1fr tracks
Test the grid item, not only the grid container
When a grid overflows, the container is not always the source. The grid item inside the track may be holding a content-based minimum width. Temporarily add min-width:0 to the grid children. If the scrollbar disappears, the grid needed shrink permission at the item level.
Related: Try this in the FrontFixer Live Inspector.
Open Live Inspector→What the bug looks like
A grid column becomes wider than the container even though the layout uses 1fr.
Why it happens
A grid item has a content-based minimum size that prevents the track from shrinking.
What usually fixes it
Use min-width:0 on grid items and minmax(0, 1fr) for shrinkable tracks.
Why 1fr can still overflow
1fr is often explained as “one fraction of the available space.” That is useful, but it can hide an important detail: the browser still has to respect the minimum size rules of the track and its content. If the content inside a grid item has a large minimum width, the track may not shrink down to the number you expect.
This is why two equal grid columns can suddenly become unequal or wider than the page. The track is not being stubborn for no reason. It is trying to avoid making the content smaller than its minimum. In many layouts, that default is helpful. In responsive cards, dashboards, media objects, and article layouts, it can create horizontal scroll.
The clean fix is to be explicit. If a column should be allowed to shrink below its content’s preferred width, use minmax(0, 1fr). If a child inside the grid should be allowed to fit the track, use min-width:0. Then decide whether the content should wrap, truncate, or scroll internally.
1fr is flexibleBut it can still preserve content-based minimum sizes.minmax(0,1fr) is explicitIt tells the track the minimum can be zero.min-width:0 helps childrenIt lets grid items fit the track instead of widening it.Two 1fr columns overflow because one item is too wide
The layout says two equal columns, but one grid item contains content that refuses to shrink. The browser tries to honor that content minimum, so the track expands and the whole grid becomes wider than the parent.
Broken code
1fr without zero minimum.grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.grid > * {
/* no min-width reset */
}
Broken visual result
The second item has long content and widens the row.
Correct code
Zero minimum track.grid {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
gap: 12px;
}
.grid > * {
min-width: 0;
}
Fixed visual result
The columns share available space and the child can truncate.
minmax(0,1fr) for tracks and min-width:0 for grid items.A URL or code line makes one grid column huge
Grid layouts often hold article cards, file rows, dashboards, and settings panels. A single long URL or code path can make one column wider than intended if the item is not allowed to shrink and truncate.
Broken code
Long text sets minimum.file-grid {
display: grid;
grid-template-columns: 90px 1fr;
gap: 12px;
}
.file-url {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Broken visual result
Ellipsis is written, but the grid item still holds its content width.
Correct code
Shrinkable URL column.file-grid {
display: grid;
grid-template-columns: 90px minmax(0, 1fr);
gap: 12px;
}
.file-url {
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Fixed visual result
The URL column can shrink, so the line truncates correctly.
A card grid uses large minimum tracks
Sometimes the issue is not the grid item but the track definition itself. If the track uses a large minimum like minmax(220px, 1fr), two columns plus gap may not fit a narrow container. The grid needs either fewer columns or a safer minimum.
Broken code
Minimum tracks too large.cards {
display: grid;
grid-template-columns: minmax(220px, 1fr) minmax(220px, 1fr);
gap: 12px;
}
Broken visual result
The track minimums plus gap exceed the available width.
Correct code
Auto-fit safe columns.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
gap: 12px;
}
.cards > * {
min-width: 0;
}
Fixed visual result
The grid creates only columns that can fit the available space.
A media grid has fixed media plus long copy
A thumbnail plus text layout can be built with Grid instead of Flexbox. The fixed media column is fine, but the copy column may still need minmax(0,1fr) and min-width:0 so long titles or descriptions do not push the grid wider.
Broken code
Copy column preserves text.media-card {
display: grid;
grid-template-columns: 100px 1fr;
gap: 12px;
}
.media-copy {
white-space: nowrap;
}
Broken visual result
The fixed thumbnail plus long copy overflows the track.
Correct code
Copy column can shrink.media-card {
display: grid;
grid-template-columns: 100px minmax(0, 1fr);
gap: 12px;
}
.media-copy {
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
Fixed visual result
The text column shrinks and truncates instead of widening the page.
A production-minded CSS Grid min-width pattern
A reliable Grid system is explicit about which tracks may shrink, which children can fit the track, and how long content should behave. That usually means minmax(0,1fr) for flexible tracks, min-width:0 for grid children, and clear overflow rules for text, media, and nested components.
Premium code
Safe Grid shrink system.layout {
display: grid;
grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
gap: clamp(12px, 2vw, 24px);
max-width: 100%;
}
.layout > * {
min-width: 0;
}
.card-title,
.card-url {
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
}
Premium visual result
The tracks and children can shrink before the page width breaks.
1fr fixes everything. It makes shrink behavior explicit.Fast practical rule
If a CSS Grid layout overflows even with 1fr columns, add min-width:0 to the grid items and change flexible tracks to minmax(0,1fr). Then control long content with wrapping, ellipsis, internal scrolling, or a more responsive card pattern.
Debug checklist
- Inspect the grid that becomes wider than its parent.
- Check whether the grid uses
1frwhereminmax(0,1fr)is safer. - Add
min-width:0to direct grid children and test whether overflow disappears. - Look for long URLs, code lines, product names, and no-wrap titles inside grid items.
- Use ellipsis only after the grid item is allowed to shrink.
- Replace large fixed track minimums with content-aware
auto-fitpatterns. - Check nested cards that bring their own
min-widthor fixed width. - Test the grid inside its smallest real parent, not only on a wide desktop canvas.
min-width:0 to the grid item and see if the scrollbar disappears.1fr, but the track still respects the content minimum.When Grid should wrap instead of shrink
min-width:0 is not the only answer. Sometimes the better design is to reduce the number of columns, use auto-fit, or stack the content. If the grid contains important readable text, shrinking and truncating everything may make the layout technically fit but harder to use.
Use min-width:0 when the grid item should fit the track and the content can safely truncate, wrap, or scroll internally. Use a different grid template when the content truly needs more space. The strongest layouts combine both ideas: tracks that can shrink, items that can fit, and breakpoints that change only when the content has enough room.
Final takeaway
CSS Grid needs min-width:0 when a grid item keeps a content-based minimum size and prevents a flexible track from shrinking. A grid can use 1fr and still overflow if the item inside the track refuses to fit.
Use minmax(0,1fr) for tracks that should truly share available space, and use min-width:0 on grid children that contain long or stubborn content. Then choose the right behavior for that content: wrap it, truncate it, stack it, or let it scroll internally when necessary.