CSS grid-auto-flow Property

Beginner
5 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The grid-auto-flow property controls how auto-placed items fill a grid. Choose row or column for the fill direction, and optionally add dense to pack into earlier empty cells.

Set it on the grid container. It is not inherited. The initial value is row. Explicitly placed items (with grid-area, grid-row, or grid-column) keep their positions; only auto-placed items follow this property.

Standard-track.

Not deprecated and not experimental. Baseline Widely available since 2017. Part of modern CSS Grid Layout.

CSS Syntax

syntax.css
grid-auto-flow: [ row | column ] || dense | initial | inherit;

Use one keyword, or pair a direction with dense (for example row dense).

Property Values

ValueDescriptionTry it
rowDefault. Fill each row, then add new rowsTry it
columnFill each column, then add new columnsTry it
denseBackfill earlier holes (implies row if no direction)Try it
row denseRow flow with dense packingTry it
initialResets to rowTry it
inheritTakes the parent’s grid-auto-flowTry it

Without dense, placement is sparse: the algorithm only moves forward and may leave empty cells.

How to Use grid-auto-flow

Build a grid, leave some items auto-placed, then pick the fill direction.

  1. Set display: grid and define tracks with grid-template-columns or rows.
  2. Leave items without line placement so they auto-place.
  3. Set grid-auto-flow to row or column.
  4. Add dense only when filling holes matters more than source order.
PieceRequired?Role
Grid containerYesdisplay: grid on the parent
Auto-placed itemsYesItems without explicit line placement
Direction keywordUsuallyrow (default) or column

Live Preview

A 3×3 track grid. Items 1 and 2 span two columns, which can leave a hole. Change grid-auto-flow and watch auto-placement.

Wide tiles span two columns. With dense, later small tiles can slip into earlier gaps.

Sample
1
2
3
4
5

grid-auto-flow: row

CSS Examples

Each snippet focuses on grid-auto-flow. Use Try It Yourself for a live editor.

Example 1 — Fill by Row

The default: place items left to right, then wrap to the next row.

CSS
<style>
  section {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-auto-flow: row;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</section>
Try It Yourself

How It Works

  1. Make three columns. grid-template-columns sets the explicit tracks.
  2. Flow by row. grid-auto-flow: row fills column 1, then 2, then 3 of the first row.
  3. Add a new row. Items 4–6 start the next row the same way.
  4. Default behavior. Omitting the property gives the same result as row.

Example 2 — Fill by Column

Fill down each column first, then move to the next column.

CSS
<style>
  section {
    display: grid;
    grid-template-rows: 60px 60px;
    grid-auto-flow: column;
  }
</style>

<section>
  <div>1</div>
  <div>2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
  <div>6</div>
</section>
Try It Yourself

How It Works

  1. Fix two rows. grid-template-rows creates the vertical tracks.
  2. Flow by column. Item 1 is row 1 of column 1; item 2 is row 2 of column 1.
  3. Start new columns. Items 3–4 and 5–6 create more implicit columns.
  4. Size tip. Those new columns use grid-auto-columns (default auto).

Example 3 — Dense Packing

Let later small items fill holes left by wider items.

CSS
<style>
  section {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-auto-flow: row dense;
  }

  .wide {
    grid-column: span 2;
  }
</style>

<section>
  <div class="wide">1</div>
  <div class="wide">2</div>
  <div>3</div>
  <div>4</div>
  <div>5</div>
</section>
Try It Yourself

How It Works

  1. Leave a hole. Wide items span two columns, so a one-cell gap can appear beside them.
  2. Turn on dense. row dense lets later items look backward for a free cell.
  3. Fill the gap. A small item such as 3 can sit in that earlier empty cell.
  4. Order trade-off. Visual order may no longer match DOM order. Skip dense when reading order must stay sequential.

Edge Cases & Pitfalls

If the flow looks wrong, check placement and packing mode.

explicit

Explicit placement wins

Items with grid-area or line longhands are not moved by grid-auto-flow.

a11y

dense can change reading order

Packed items may appear out of source order. Prefer sparse flow when document order matters for accessibility.

tracks

Column flow creates implicit columns

With column, extra columns are sized by grid-auto-columns. With row, extra rows use grid-auto-rows.

sparse

Sparse leaves holes on purpose

Without dense, the algorithm never backtracks. Empty cells beside a spanning item can stay empty.

alone

dense alone means row dense

If you omit row or column, the direction defaults to row.

Browser Support

grid-auto-flow is a browser CSS property for CSS Grid auto-placement. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

grid-auto-flow

Supported in Chrome 57+, Firefox 52+, Safari 10.1+, and Edge 16+. Internet Explorer does not support modern Grid.

97% Global support
Google Chrome 57+
Full support
Mozilla Firefox 52+
Full support
Apple Safari 10.1+
Full support
Microsoft Edge 16+
Full support
Opera 44+
Full support
Samsung Internet 6.2+
Full support
Internet Explorer No modern Grid
Not supported
grid-auto-flow Widely supported

Bottom line: Safe in current browsers. Use row or column for direction; add dense only when packing holes is worth reordering items.

Key Takeaways

  • Role: steer auto-placement by row or column, with optional dense packing.
  • Initial: row. Not inherited.
  • Auto only. Explicit line placement ignores this property.
  • Dense packs holes but can reorder items visually.

One line: grid-auto-flow is the map for how unplaced grid items walk through the tracks.

Frequently Asked Questions

It controls how auto-placed grid items fill the grid: by row or by column, and whether empty holes can be packed with dense.
The initial value is row. Items fill each row in turn and add new rows as needed.
row fills across a row first, then moves to the next row. column fills down a column first, then moves to the next column.
dense lets later smaller items fill earlier empty cells left by larger items. Items may appear out of source order. Without dense, placement only moves forward (sparse).
No. Items with grid-area, grid-row, or grid-column keep those positions. Only auto-placed items follow grid-auto-flow.
It is Baseline Widely available: Chrome 57+, Firefox 52+, Safari 10.1+, and Edge 16+. Internet Explorer does not support modern Grid. It is a browser CSS property, not a Node.js feature.

Next: grid-auto-rows

Size implicitly created row tracks.

grid-auto-rows tutorial →

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.

8 people found this page helpful