CSS grid-auto-flow Property

Beginner
⏱️ 6 min read
📚 Updated: Jun 2026
🎯 4 Examples
Layout

What You’ll Learn

The grid-auto-flow property controls how items that are not explicitly placed are automatically arranged inside a CSS grid.

01

Auto-place

Item flow.

02

row

Default flow.

03

column

Vertical fill.

04

dense

Fill gaps.

05

Implicit

New tracks.

06

Container

Grid parent.

Introduction

The grid-auto-flow property in CSS is used to control how auto-placed items are inserted into the grid. When items are not explicitly positioned, the grid-auto-flow property determines their placement.

This property is particularly useful in creating responsive and dynamic grid layouts.

Definition and Usage

Set grid-auto-flow on a grid container with display: grid. Items without explicit placement follow the flow direction you choose. Use row for classic left-to-right layouts, column for vertical-first layouts, and add dense to backfill empty cells.

💡
Beginner Tip

grid-auto-flow only affects auto-placed items. If you set grid-column or grid-area on an item, that item keeps its explicit position.

📝 Syntax

The syntax for the grid-auto-flow property is as follows:

syntax.css
element {
  grid-auto-flow: value;
}

Basic Example

grid-auto-flow-basic.css
.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-flow: row;
}
grid-auto-flow: row; grid-auto-flow: column; grid-auto-flow: row dense;

Default Value

The default value of the grid-auto-flow property is row.

Syntax Rules

  • Applies to grid containers only, not individual grid items.
  • Accepts a flow keyword (row or column) plus an optional dense keyword.
  • Only affects auto-placed items; explicitly positioned items are unchanged.
  • The property is not inherited.
  • Works with grid-auto-rows and grid-auto-columns to size new implicit tracks.

⚡ Quick Reference

QuestionAnswer
Initial valuerow
Applies toGrid containers
InheritedNo
ControlsAuto-placement direction
Optional keyworddense

💎 Property Values

ValueDescription
rowPlaces items by filling each row, adding new rows as necessary
columnPlaces items by filling each column, adding new columns as necessary
row densePlaces items by filling each row, trying to fill in gaps in earlier rows if possible
column densePlaces items by filling each column, trying to fill in gaps in earlier columns if possible

👀 Live Preview

Default row flow with five items in a three-column grid (items 4–5 wrap to row 2):

1
2
3
4
5

Examples Gallery

Compare row and column auto-flow, then see how dense packing fills gaps left by spanning items.

🔢 Flow Direction

Start with the reference example — row flow versus column flow side by side.

Example 1 — Row vs Column Auto Flow

Create two grids and compare how items are placed with row and column.

grid-auto-flow-row-column.css
.row { grid-auto-flow: row; }
.column { grid-auto-flow: column; }
Try It Yourself

How It Works

With row, items fill left to right then wrap to the next row. With column, items fill top to bottom in each column before moving to the next column.

Example 2 — Default Row Flow

Five items in a three-column grid using the default row placement.

grid-auto-flow-row.css
.container {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: 100px;
  grid-auto-flow: row;
  gap: 10px;
}
Try It Yourself

How It Works

Items 1–3 fill the first row. Items 4 and 5 start a second row because no explicit placement was set.

📈 Dense Packing

Use dense to backfill holes when some items span multiple cells.

Example 3 — row dense vs row

Compare normal row flow with dense packing when a wide item leaves a gap.

grid-auto-flow-dense.css
.wide { grid-column: span 2; }
.dense { grid-auto-flow: row dense; }
Try It Yourself

How It Works

When a spanning item leaves a hole, normal row flow may skip it. row dense tries to place later items into earlier empty cells.

Example 4 — Horizontal Strip with Column Flow

Build a horizontal layout where items fill columns first, useful for carousels and toolbars.

grid-auto-flow-column.css
.toolbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  gap: 0.75rem;
}
Try It Yourself

How It Works

Column auto-flow stacks items horizontally. Each button becomes its own implicit column sized to its content.

♿ Accessibility

  • Keep DOM order meaningful even when dense changes visual placement.
  • Do not rely on visual grid position alone to convey relationships; use headings and labels.
  • Test keyboard tab order when column flow rearranges items visually.
  • Avoid dense packing when reading order must strictly match source order.
  • Ensure interactive controls stay large enough in column-flow toolbars.

🧠 How grid-auto-flow Works

1

Grid template is defined

grid-template-columns and rows set the starting tracks.

Template
2

Auto-placed items arrive

Items without explicit placement enter the grid in document order.

Auto items
3

grid-auto-flow directs placement

The browser fills rows or columns and optionally backfills gaps with dense.

Flow
=

Flexible auto layout

Items land in predictable positions without manual placement on every cell.

🖥 Browser Compatibility

The grid-auto-flow property is supported in most modern browsers, including recent versions of Chrome, Firefox, Safari, Edge, and Opera.

Baseline · Modern browsers

grid-auto-flow everywhere

Auto-placement flow works in all major modern grid implementations.

97% Modern browser support
Google Chrome 57+ · Desktop & Mobile
Full support
Mozilla Firefox 52+ · Desktop & Mobile
Full support
Apple Safari 10.1+ · macOS & iOS
Full support
Microsoft Edge 16+ · 79+ Chromium
Full support
Opera 44+
Full support
grid-auto-flow property 97% supported

Bottom line: Safe for modern projects. Test dense layouts for reading-order impact.

🎉 Conclusion

The grid-auto-flow property is an essential tool for web developers working with CSS Grid layouts. It provides flexibility in how auto-placed items are arranged within the grid, allowing for more dynamic and responsive designs.

By understanding and utilizing this property, you can create more efficient and visually appealing grid layouts for your web projects. Start with row, then experiment with column and dense when you need tighter packing.

💡 Best Practices

✅ Do

  • Use row for standard page layouts
  • Use column for horizontal strips and toolbars
  • Pair with grid-auto-rows or grid-auto-columns
  • Test dense layouts for tab and screen reader order
  • Keep explicit placement for hero or featured items

❌ Don’t

  • Apply on grid items instead of containers
  • Use dense when visual order must match DOM order
  • Expect it to move explicitly placed items
  • Forget implicit track sizing properties
  • Overuse dense on content-heavy pages

Key Takeaways

Knowledge Unlocked

Five things to remember about grid-auto-flow

Use these points when controlling auto-placement.

5
Core concepts
row 02

Default row

Left to right.

Default
col 03

Column flow

Top to bottom.

Pattern
dense 04

Fill gaps

Backfill holes.

Keyword
explicit 05

Auto only

Not placed items.

Scope

❓ Frequently Asked Questions

grid-auto-flow controls how items that are not explicitly placed are automatically inserted into the grid, including whether they fill rows or columns first.
The default value is row, which fills each row from left to right before starting a new row.
row fills rows first and adds new rows as needed. column fills columns first and adds new columns as needed.
dense tells the browser to backfill earlier gaps in the grid when placing auto-positioned items, instead of leaving empty cells.
No. Items with explicit placement such as grid-column or grid-area keep their assigned positions. grid-auto-flow only affects auto-placed items.

Practice in the Live Editor

Open the HTML editor, switch between row and column flow, and watch auto-placement change.

HTML Editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

5 people found this page helpful