Grid Auto Placement Property

Last updated: 2026-09-13

grid-auto-flow Grid Auto Placement Property

The grid-auto-flow property controls how grid items that are not explicitly positioned are placed automatically. It decides whether the items fill by row or by column, and whether the dense packing mode is enabled to fill the gaps in the layout. The property has a direct impact on the overall ordering of the grid.

Category
Initial Valuerow
InheritedNo
Applies To
Animation Type
CSS VersionCSS3
StatusStandard

📝 Syntax

grid-auto-flow: row | column | row dense | column dense;

⚙️ Values

ValueTypeDescription
row | column | row dense | column denseKeywordAuto placement direction and dense packing

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
grid-auto-flow v57 v16 v52 v10.1 v44
Supported in all major browsers
Tip: row fills the grid row by row (the default); column fills it column by column.
Tip: The dense keyword enables dense packing: smaller items that come later move back to fill the gaps left by larger items, but the visual order may change.

❓ FAQ

QWhen should I use the dense mode?
AUse dense when the items have different sizes and the auto placement leaves gaps; it lets the later, smaller items move back to fill the earlier holes, maximizing the use of space. But dense pushes the visual order away from the DOM order, while screen readers and keyboard navigation still follow the DOM, so the reading may jump around. Be careful in accessibility-sensitive contexts.
QWhat does grid-auto-flow: column look like?
AItems first fill the first column from top to bottom, then move to the next column, flowing in a direction perpendicular to the default row-first filling. With column, the extra items create implicit columns to the right rather than implicit rows below, which is the orientation you want for horizontally arranged lists. It suits column-oriented content such as vertical reading flows, timelines and columns of related cards. You can also write grid-auto-flow: column dense to enable dense packing while filling column by column.
QHow do I build a masonry layout with CSS Grid?
AA common approach is grid-auto-flow: row dense together with cards of different heights given grid-row: span 2 or span 3, combined with grid-auto-rows for uniform row heights; dense then fills the holes. But dense disrupts the visual/DOM order and affects accessibility. Note that the native grid masonry implementation is still experimental and behind a flag in some engines, so for production sites column-count remains the more portable fallback when preserving order and browser coverage matter.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏