liveBook · Manning

Implicit grid

As explained in CSS in Depth, Second Edition

Implicit grid placement is CSS Grid's automatic placement of items into tracks that are created or selected beyond the explicitly defined grid.

Implicit grid placement lets CSS Grid handle items whose exact number or position is unknown. Defining tracks with grid-template-* creates the explicit grid; items placed beyond those tracks cause additional implicit tracks to be generated automatically. section 5.4

The browser applies these rules when implicit tracks are needed:

  • Implicit tracks default to auto sizing, growing enough to contain their items. section 5.4
  • grid-auto-columns and grid-auto-rows set a different size for all implicit tracks, such as 1fr. section 5.4
  • Negative grid-line numbering still begins from the bottom or right edge of the explicit grid. section 5.4
  • Automatic placement is useful when many items must flow naturally, especially when their count comes from a database. section 5.4 section 5.7

Photography portfolio

Define responsive columns while leaving the rows implicit: .portfolio { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); grid-auto-rows: 1fr; grid-gap: 1em; }. As images wrap onto new lines, CSS Grid adds rows automatically, so the layout does not depend on a fixed number of photographs. section 5.4

Figure 5.11 If a grid item is placed outside the declared grid tracks, implicit tracks will be added to the grid until it can contain the item.
figure

See how placing an item beyond the declared tracks causes CSS Grid to add implicit tracks until the item fits. section 5.4

How CSS in Depth, Second Edition covers it

How deep it goes
Defines track generation, default sizing, auto-track controls, and negative-line behavior without detailing the full placement algorithm.
Examples
Uses a photography portfolio with responsive columns, implicit rows, wrapping images, and grid-auto-rows: 1fr.
What it assumes
Assumes awareness of grid-template-* track definitions and grid item placement.
What you can do after
Build it from scratch with CSS Grid for a variable number of items using automatically generated rows or tracks.
How it connects
Connects CSS Grid tracks and grid lines with auto-fill, auto-fit, flexbox, and automatic item placement.

Also explained in

Compare how 2 books explain implicit grid →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of CSS in Depth, Second Edition. The section links point to the parts of the book it draws on.