The Implicit Grid and Auto-Placement: grid-auto-rows, grid-auto-flow and dense
How grid places items you haven't positioned: the auto-placement algorithm, sizing implicit tracks with grid-auto-rows and grid-auto-columns, row and column flow with grid-auto-flow, filling holes with dense and its accessibility cost.
kvi5hnuCode Sprout team member7 min readOn this page
Most grids don't place every item. You define the columns, and the browser puts each item into the next free cell, creating rows as needed. This auto-placement is what makes a card list or gallery need only two lines of CSS. This article covers how it works, how the rows it creates are sized, and how to change its direction and packing.
The implicit grid
The tracks you define are the explicit grid (article 66). Tracks the browser adds, for extra items or items placed beyond the explicit lines (article 68), form the implicit grid. Implicit tracks are sized by two properties:
| Property | Sizes | Initial value |
|---|---|---|
grid-auto-rows | implicit rows | auto |
grid-auto-columns | implicit columns | auto |
.gallery {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr));
grid-auto-rows: 12rem; /* every row the items create is 12rem */
}
.feed { display: grid; grid-auto-rows: minmax(6rem, auto); } /* at least 6rem, taller if needed */
Several values make a repeating pattern. Tested in Chrome: with grid-auto-rows: 10px 20px, rows alternate 10px, 20px, 10px... Implicit columns work the same way: in a grid with one explicit 100px column and grid-auto-columns: 30px, an item placed in column 3 creates two 30px implicit columns.

The implicit rows restart the 24px 40px pattern right after the explicit row, and the empty 30px column exists only so that line 3 can be reached.
The auto-placement algorithm
The browser places items in this order:
- Items with a definite position on both axes (such as
grid-area: mainorgrid-column: 2; grid-row: 1) are placed first, wherever they're told. - Items locked to a row (in row flow), with a
grid-rowbut no column, go into that row. - Everything else is placed in source order (or
order, article 64): a cursor moves along the rows, left to right in English, and each item goes into the first position where it fits without overlapping anything already placed. New rows are created when needed.
Tested in Chrome: in a three-column grid where the third item is fixed at grid-column: 2; grid-row: 1, the first two auto items go to columns 1 and 3, around it.
Items with span need enough free cells in a row. Tested in Chrome: in three columns, items 1 and 2 fill the first two cells; item 3, with grid-column: span 2, doesn't fit in the one cell left, so it moves to row 2, leaving a hole. Item 4 goes after it.

grid-auto-flow
| Value | Effect |
|---|---|
row (initial) | fill each row, then add rows |
column | fill each column, then add columns |
dense or row dense | fill rows, and fill earlier holes with later items that fit |
column dense | the same, by column |
column flow
With grid-auto-flow: column, items fill the rows of the first column, then move to the next column, and implicit columns are created. You need a fixed number of rows:
.list { display: grid; grid-template-rows: repeat(4, auto); grid-auto-flow: column; grid-auto-columns: 12rem; }
Tested in Chrome: with two rows and grid-auto-columns: 50px, items 1 and 2 form the first column, 3 and 4 the second, and item 5 starts a third. It's useful for lists that read top to bottom, then across; for long text in columns, multi-column layout (article 73) is usually better, because it balances the columns automatically.

In the last grid the fixed item is placed before any auto item, so the cursor flows around it; the visual order 1 3 2 no longer matches the HTML.
dense packing
By default, the cursor never goes back, so holes stay. That's sparse packing, and it keeps items in source order. dense restarts the search from the beginning for each item, so later items fill earlier holes. Tested in Chrome: with grid-auto-flow: dense, item 4 in the example above moves up into row 1.
dense gives tidy galleries with mixed sizes, but it breaks the link between the visual order and the HTML order: items jump ahead of others, while the keyboard focus order and screen readers still follow the HTML (article 64). Use it for images or items where order doesn't matter, and avoid it for content that's read in sequence or contains links people tab through. Where reading-flow is supported (Chrome 137+), reading-flow: grid-rows makes focus follow the visual rows.
body { font: 0.8rem system-ui, sans-serif; margin: 1rem; }
.gallery {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-auto-rows: 3rem;
gap: 0.4rem;
margin-top: 0.75rem;
}
body:has(#dense:checked) .gallery { grid-auto-flow: dense; }
.gallery div {
display: grid; place-items: center;
background: #f4efe6; border: 1px solid #8a3b12; border-radius: 6px;
}
.gallery .wide { grid-column: span 3; background: #fde2e1; border-color: #b3261e; }
.gallery .tall { grid-row: span 2; background: #dff0e5; border-color: #2f7d4f; }
Without dense, the three-column item 3 can't fit after 1 and 2, so it starts a new row and leaves two empty cells. With dense, items 4 and 5 move back into earlier holes, and the numbers are no longer in reading order.
Mixing placed and auto-placed items
Placed items take their cells first, and auto-placed items flow around them, which is handy for a featured item:
.products { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.products .featured { grid-column: 3 / 5; grid-row: 1 / 3; } /* top right, 2 × 2 */
The other products fill the remaining cells in order, around the featured one.
The grid shorthand and implicit tracks
grid-auto-flow, grid-auto-rows and grid-auto-columns can also be set by the grid shorthand, which resets all of the explicit and implicit grid properties. Article 70 covers it; in practice, the separate properties are clearer.
What's current
- Auto-placement,
grid-auto-rows,grid-auto-columnsandgrid-auto-flowwithdensework in all browsers. reading-flow: grid-rows,grid-columnsandgrid-order(Chrome 137+) fix the focus order of reordered grids.- Grid lanes (article 72) are a new layout for masonry, where items pack into the shortest column instead of rows.
Common questions
Why is there a gap in my grid?
A spanning item didn't fit in the remaining cells of a row, so it moved to the next row. Use grid-auto-flow: dense, or adjust the spans.
How do I size the rows that the grid creates automatically?
grid-auto-rows, for example grid-auto-rows: minmax(8rem, auto).
Is dense bad for accessibility?
It can be: it moves items out of source order visually, so keyboard and screen reader users meet them in a different order. Use it only where order doesn't matter.
How do I make items flow down columns instead of across rows?
grid-auto-flow: column, with a fixed number of rows in grid-template-rows.
Summary
- Tracks created for extra or out-of-range items form the implicit grid, sized by
grid-auto-rowsandgrid-auto-columns, which can repeat a pattern. - Placed items go first; the rest are auto-placed in source order into the first cells where they fit.
grid-auto-flow: columnfills columns and creates implicit columns.- Spans can leave holes;
densefills them with later items, at the cost of source order. - Mix explicitly placed items with auto-placed ones freely: auto-placement flows around them.
Practice questions
A grid has the rule below and holds 10 items. How many rows are there, and how tall is each?
.g { display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 5rem 2rem; }
Answer
Four rows (3 + 3 + 3 + 1), alternating 5rem, 2rem, 5rem, 2rem.
In a four-column grid, item 1 has grid-column: span 3, item 2 has grid-column: span 2, and item 3 is a normal item. Where does each go, with and without dense?
Answer
Item 1 takes row 1, columns 1–3. Item 2 doesn't fit in the one cell left, so it goes to row 2, columns 1–2. Without dense, item 3 follows it in row 2, column 3. With dense, item 3 fills the hole at row 1, column 4.
A blog's list of article cards uses grid-auto-flow: dense to avoid gaps. What's the problem?
Answer
Cards can appear out of their HTML order, so the reading and tab order no longer match what's on screen, and readers may miss that articles are in date order. Avoid dense for content read in sequence, or keep spans consistent so there are no holes.
Write CSS for a list that fills three rows of a column, then continues in a new 10rem column to the right.
Answer
.list {
display: grid;
grid-template-rows: repeat(3, auto);
grid-auto-flow: column;
grid-auto-columns: 10rem;
}
Previous: Placing Grid Items: Line Numbers, Spans, Named Lines and grid-template-areas
Next: Aligning Grid Items and Tracks, Overlapping Items, and the grid Shorthand

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.