Why is a CSS grid column wider than its declared fraction?
Quick answer
A plain 1fr track has an automatic minimum that can be based on the grid item’s content, so its track may resist shrinking even when you expect the available space to be divided into fractions. If that content-based minimum is the problem, try minmax(0, 1fr) for the affected track. It keeps a flexible maximum but explicitly allows a zero minimum. [S1]
The question, the details, the next step.
A practical checklist
Reproduce the layout at the width where the column looks too wide.
Temporarily remove or shorten long content in the affected grid item and compare.
Try
minmax(0, 1fr)on the track that needs to shrink below its content-based minimum.Retest with representative content and check the result at the intended container width.
Keep other tracks unchanged unless testing shows they need the same minimum constraint.
A few more useful answers
Does `minmax(0, 1fr)` make the column fixed-width?
No. Its maximum remains flexible; the zero is an explicit minimum that lets the track shrink below a content-based minimum. [S1]
Should every grid column use `minmax(0, 1fr)`?
Not necessarily. Apply it to tracks that need to shrink below their content-based minimum, and test the layout with your actual content.
Does this fix explain every case of a wider-than-expected column?
No. It addresses the automatic minimum associated with a plain 1fr track. The cited guidance does not establish that this is the cause in every layout. [S1]
Sources
References used for this guide.
- [S1] grid-template-columns CSS property - CSS | MDN developer.mozilla.org · Checked
