CSSHard
What is the difference between auto-fit and auto-fill in Grid?
By FrontendPro Editorial Team Updated 8/7/2026
#css#grid#responsive
Answer
css
.grid { display: grid; gap: 16px; }
.fill { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.fit { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
When there are fewer items than columns that would fit:
auto-fillkeeps the empty tracks → items stay their size, packed left.auto-fitcollapses empty tracks to 0 → the remaining items stretch across the full width.
They behave identically once a row is full. If you don't want one or two cards ballooning, choose auto-fill.
