What is the difference between auto-fit and auto-fill in CSS Grid?

Both auto-fit and auto-fill create as many grid tracks as fit in the available space. The difference appears when the grid has fewer items than available tracks. Auto-fit collapses empty tracks, while auto-fill keeps their reserved columns.
With auto-fit, occupied tracks can expand into the space left by collapsed empty tracks. This is usually desirable for a responsive card grid where a short final row should stretch. With auto-fill, invisible empty tracks remain part of the grid and hold their share of the space.
.grid-fit {
grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}
.grid-fill {
grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
}
The two patterns often look identical while enough items fill every track, which makes the difference easy to miss in a component catalog. Test with one item, a partially filled row and many items. Developer tools can display the explicit grid tracks and show the empty columns that auto-fill preserves.
Choose auto-fit when existing items should use spare width. Choose auto-fill when maintaining the potential column structure matters, such as a layout that reserves positions for items added later. In both cases, make the minimum small enough for the narrowest container or use a bound such as min(100%, 16rem). Keep the layout rule beside the component and document why the threshold or constraint exists. This reduces accidental overrides and gives future editors a concrete condition to retest after content changes. Add this case to responsive regression tests with long content, browser zoom and at least one narrow embedded container. Record the expected wrapping and focus behavior so later component changes can be checked against a known result.