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.
Fundamentals
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.
Foundation
📝 Syntax
The syntax for the grid-auto-flow property is as follows:
Column auto-flow stacks items horizontally. Each button becomes its own implicit column sized to its content.
A11y
♿ 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.
Compatibility
🖥 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 Chrome57+ · Desktop & Mobile
Full support
Mozilla Firefox52+ · Desktop & Mobile
Full support
Apple Safari10.1+ · macOS & iOS
Full support
Microsoft Edge16+ · 79+ Chromium
Full support
Opera44+
Full support
grid-auto-flow property97% supported
Bottom line: Safe for modern projects. Test dense layouts for reading-order impact.
Wrap Up
🎉 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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about grid-auto-flow
Use these points when controlling auto-placement.
5
Core concepts
↔01
Auto-place
Item direction.
Purpose
row02
Default row
Left to right.
Default
col03
Column flow
Top to bottom.
Pattern
dense04
Fill gaps
Backfill holes.
Keyword
explicit05
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.