Auto-fit
A CSS Grid repeat() keyword that creates as many repeated tracks as fit within the available space and collapses empty tracks.
CSS in Depth, Second Edition
Auto-fill and auto-fit are CSS Grid track-repetition keywords that determine how many tracks are generated to fit available space.
- How it is used
- Builds responsive card and portfolio grids whose column count follows available space and item constraints.
- How deep it goes
- Explains repeat(), minmax(), flexible track sizing, empty-track behavior, and breakpoint use without detailing browser layout internals.
- Examples
- Demonstrates portfolio photographs and chicken cards arranged in adaptive grids.
- What you can do after
- Apply it via CSS Grid to build adaptive columns without manually specifying each viewport’s column count.
Math for Web Design
auto-fit is a CSS Grid repeat() keyword that creates fitting tracks and collapses empty tracks so available space can be redistributed.
- How it is used
- Builds responsive Grid layouts that adapt track counts and redistribute space without querying viewport width.
- How deep it goes
- Explains repetition math, gap subtraction, empty-track collapse, and flexible redistribution through runnable CSS examples.
- Examples
- Demonstrates two cards in an 850px container, contrasting 212.5px auto-fill tracks with 425px auto-fit tracks.
- What you can do after
- Build responsive card grids with repeat(auto-fit, minmax(...)) and choose whether empty tracks collapse or remain.
What to know first
- flexboxFlexbox is a CSS one-dimensional layout model for arranging, sizing, aligning, and distributing items along a row or column.
- media queryA media query is a CSS conditional rule that applies styles when specified media types or presentation-environment features match.
Related concepts
- auto-fillalternative to · A CSS Grid repeat() keyword that creates as many repeated tracks as fit within the available space, retaining empty tracks.
- CSS Gridused by · CSS Grid is a CSS layout system for arranging elements in two-dimensional rows and columns.
- repeat()used by · The CSS repeat() function specifies a repeated sequence of grid track sizes or patterns, using a fixed or automatically determined repetition count.
- gridconfigures · A grid is a regular arrangement of positions or cells organized by rows and columns or by fixed neighboring relationships.
- fr unituses · The CSS fr unit is a flexible Grid track-sizing unit representing a share of the grid container’s leftover free space.
Questions about auto-fit
What is auto-fit?
A CSS Grid repeat() keyword that creates as many repeated tracks as fit within the available space and collapses empty tracks.
Which Manning books explain auto-fit?
CSS in Depth, Second Edition and Math for Web Design.
What should I know before learning auto-fit?
Manning books that teach auto-fit usually introduce flexbox and media query first.
What is the difference between auto-fit and auto-fill?
A CSS Grid repeat() keyword that creates as many repeated tracks as fit within the available space and collapses empty tracks. A CSS Grid repeat() keyword that creates as many repeated tracks as fit within the available space, retaining empty tracks.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

