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

Automatic Placement: How Grid Items Flow

Understanding the default auto-placement algorithm that fills grid cells row by row.

Automatic Placement: How Grid Items Flow

You'll learn: How CSS Grid automatically places items into cells when you don't specify exact positions.

When you create a grid with grid-template-columns and grid-template-rows, but don't tell each item where to sit, the browser uses an auto-placement algorithm to fill the grid. Think of it like reading a book: Grid fills cells left-to-right across the first row, then moves to the next row and repeats.

The Default Flow

By default, Grid places items row by row (the "row-dense" algorithm). The first grid item goes into the first cell (row 1, column 1), the second item goes into the next available cell to the right, and so on. When a row fills up, the next item starts on a new row.

.container {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

With this setup and six items, Grid automatically arranges them:

  • Items 1, 2, 3 → First row
  • Items 4, 5, 6 → Second row

You don't need to tell each item grid-column or grid-row—the browser figures it out.

What Happens with More Items?

If you define a 3-column grid but have 10 items, Grid creates implicit rows (remember: implicit vs explicit grid?) to hold the extras. The auto-placement continues flowing down as many rows as needed.

This automatic behavior makes Grid incredibly powerful for dynamic content where you don't know the exact number of items in advance—like image galleries or product listings.

Key Takeaway: Grid's auto-placement algorithm fills cells row by row, left to right, automatically creating new rows as needed—no manual positioning required for simple layouts.