Course contentsShow
← Web Development
Lesson 354 of 2,9826. CSS GridFree lesson

grid-auto-flow Direction

Controlling whether auto-placed items flow by row or column.

grid-auto-flow Direction

What you'll learn: How to control whether auto-placed grid items flow into rows or columns first.

When you don't explicitly position every grid item, CSS Grid's auto-placement algorithm kicks in to place items automatically. By default, items flow row by row (left to right, then to the next row), but you can change this direction.

The Core Concept

The grid-auto-flow property controls the direction of automatic item placement. Think of it like reading order: English text flows left-to-right across rows, but some languages flow top-to-bottom down columns. Grid gives you the same flexibility.

Two main values:

  • grid-auto-flow: row — (default) Items fill the first row completely, then move to the second row, and so on
  • grid-auto-flow: column — Items fill the first column completely, then move to the second column, and so on
.grid-container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 100px);
  gap: 10px;
  grid-auto-flow: column; /* items flow down columns instead of across rows */
}

With row (default), six items would arrange like: 1 2 3 on top, 4 5 6 on bottom.

With column, those same six items arrange like: 1 4 in column one, 2 5 in column two, 3 6 in column three.

When to Use This

Use column when your layout logic groups items vertically — like a multi-column news layout or form fields arranged in columns. Most layouts stick with the default row value.

Key Takeaway: grid-auto-flow determines whether auto-placed items fill across rows first (row) or down columns first (column), giving you control over the natural flow direction of your grid.