CSS Reference ยท Grid
The grid-auto-flow property
Reference for the CSS grid-auto-flow property: control how auto-placed grid items fill rows or columns, and how dense packing backfills gaps.
The grid-auto-flow property controls how the browser places grid items that have no explicit position. It chooses the direction the grid fills (row by row, or column by column) and whether the algorithm may go back and fill holes left by larger items (dense).
CSS
.tiles { display: grid; grid-auto-flow: row dense; }
Try it
Syntax
CSS
grid-auto-flow: [ row | column ] || dense;
- Initial value:
row - Applies to: grid containers
- Inherited: no
- Animatable: no
- Computed value: as specified
Values
| Value | Description |
|---|---|
row |
Fill each row in turn, adding new rows when needed. The default. |
column |
Fill each column in turn, adding new columns (sized by grid-auto-columns). |
dense |
Allow later, smaller items to fill earlier gaps. Can be combined with row or column. |
row dense / column dense |
Direction plus dense packing. |
Usage notes
- Dense changes visual order. Items can appear out of source order. Keyboard focus and screen readers still follow the HTML, which can be confusing; avoid
densefor content where order matters. - Only auto-placed items are affected. Items with both an explicit row and column stay where you put them.
columnneeds a row template. Withgrid-auto-flow: columnsetgrid-template-rows(or a container height) so the items know when to wrap to the next column.- Not the same as
flex-direction. The property only decides where new items go; it does not alter the tracks. - Large reorderings are costly to understand. Prefer
densefor galleries of similar tiles.
Browser support
Supported in all current browsers.
Related
grid-auto-columnsandgrid-auto-rows- implicit track sizesgrid-column-start- explicit placement- Lesson: Placing Grid Items