CSS Fix
Fix CSS Grid breaking on mobile without fighting the layout.
When a grid looks perfect on desktop but starts crushing cards, overflowing sideways, or behaving strangely on phones, the problem is usually not Grid itself. It is usually rigid column sizing, aggressive track definitions, or child elements refusing to shrink.
- Common production bug
- Usually a track sizing issue
- Often fixed with simpler rules
What the bug looks like
Cards get squeezed, text spills out, horizontal scroll appears, or the grid feels cramped and unstable on smaller screens.
Why it happens
The track sizing is too ambitious for the screen, or one child inside the grid is wider than the grid can safely absorb.
What usually fixes it
Looser column sizing, fewer columns on smaller screens, and children that are allowed to shrink properly inside the grid.
Why CSS Grid gets blamed unfairly
Grid often becomes the scapegoat because the visible break happens in the layout. But Grid is usually just enforcing the track logic you defined. If the columns demand more width than the screen has, Grid will not magically save the design for you.
That is why the smartest fix is often not more complexity. It is reducing rigidity.
Common signs the track sizing is too aggressive
Recommended fix
Safer mobile patternThis is a stable starting point for most card grids. It uses simple desktop columns, gives children room to shrink, and switches cleanly to one column on smaller screens.
.cards {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 24px;
}
.card {
min-width: 0;
}
.card img {
max-width: 100%;
height: auto;
display: block;
}
@media (max-width: 768px) {
.cards {
grid-template-columns: 1fr;
gap: 16px;
}
}
Common broken version
Too much minimum widthThis looks elegant, but it often causes trouble when the minimum size is too ambitious for a phone.
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
gap: 24px;
}
Why this breaks
A phone viewport may not have enough usable space for a 320px track once padding, gaps, and parent width are factored in. That can lead to overflow or awkward compression.
Simple rule: if mobile is breaking, test whether your minimum column size is simply too ambitious.
minmax() is doing too much
A smart-looking rule can still be too rigid if the minimum width is larger than the layout can really support on mobile.
Children are wider than the grid expects
Long text, media, or nested layouts can create overflow even when the track definition looks reasonable.
The grid never gets a clean mobile fallback
Many layouts work better with fewer columns or one column on mobile instead of trying to be “smart” at every width.
Fast practical rule
If the grid is breaking on mobile, reduce complexity first. Fewer columns, smaller gaps, and children with min-width: 0; solve more Grid bugs than people expect.
Debug checklist
- Check whether the parent container has padding that reduces the real usable width.
- Inspect the grid track definition and look for overly large
minmax()values. - Add
min-width: 0;to grid children that contain long text, images, or nested flex items. - Test whether buttons, code blocks, or media elements are forcing horizontal overflow.
- At mobile breakpoints, reduce the number of columns before trying more advanced fixes.
min-width: 0; to grid items when nested content is causing overflow.
Good mobile-friendly pattern
For many production layouts, explicit desktop columns plus a simple mobile fallback is more stable than trying to make one clever rule handle every screen size.
In real projects, predictable usually beats clever.
Alternative pattern
Simple and stable.cards {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 20px;
}
@media (max-width: 640px) {
.cards {
grid-template-columns: 1fr;
}
}
Final takeaway
CSS Grid breaking on mobile is rarely a sign that Grid itself is unreliable. It is usually a sign that the layout is asking too much from the available width.
Relax the track sizing, let children shrink, and give mobile a simpler fallback. Once you do that, the grid usually becomes much easier to trust.
Want more fixes like this?
Browse more CSS debugging guides or jump straight to the full FrontFixer library.