How can I keep a responsive layout from overflowing at its narrowest width?
Quick answer
At the narrowest width, check the container’s usable width, each grid track’s minimum, the gaps, and any item with a fixed or content-based minimum. If their combined minimums exceed the space available, reduce the track minimum or change the arrangement when the content no longer fits. Grid items can have automatic minimum sizes based on their content, so inspect the items as well as the tracks. [S3]
The question, the details, the next step.
A practical checklist
Measure the container’s usable width after padding.
Add required track minimums and gaps; compare the total with usable width.
Inspect fixed widths, long unbroken content, and item minimum sizes.
Choose the point where the current arrangement stops fitting, then adapt the tracks or stack the content.
Test the narrowest intended width and widths on both sides of the change.
A few more useful answers
Should I always use a media query to prevent grid overflow?
No. Automatic track creation can adapt the number of columns to available space, but the chosen minimum track size and gaps still need to fit. Use a media query when a different arrangement better suits the content.
Is there a standard breakpoint for switching to one column?
No universal breakpoint is established here. Calculate when your chosen track minimums and gaps stop fitting in the usable container width, then test around that point.
Sources
References used for this guide.
- [S1] Realizing common layouts using grids — CSS | MDN developer.mozilla.org · Checked
- [S2] CSS grid layout — Learn web development | MDN developer.mozilla.org · Checked
- [S3] min-width — CSS | MDN developer.mozilla.org · Checked
