grid-auto-flow
W3C CSS Snapshot 2026
Tell automatic placement whether to fill rows or columns first and whether to backfill gaps.
On this page
Syntax and values
| Value or syntax | What it does |
|---|---|
row | The default. Fills rows and creates extra rows when needed. |
column | Fills columns and creates extra columns when needed. |
dense / row dense / column dense | Can move later items into earlier gaps, changing the visual order. Keep the HTML order logical. |
Try the example
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>grid-auto-flow example</title>
<style>
.layout { display: grid; width: min(100%, 320px); border: 2px solid teal; box-sizing: border-box; }
.layout > div { padding: 8px 12px; background: #def5f5; color: #123; border: 1px solid #81b9b5; box-sizing: border-box; }
.layout { grid-template-columns: repeat(3, 1fr); grid-auto-flow: row dense; }
.first, .second { grid-column: span 2; }
</style>
</head>
<body>
<div class="layout">
<div class="first">A</div>
<div class="second">B</div>
<div>C</div>
</div>
</body>
</html>
What to expect C fills the gap after A in the first row. Remove dense to see C stay after B.