Flexbox & Grid

Grid Auto Flow

Utilities for controlling how elements in a grid are auto-placed.

Quick reference

Class Properties
grid-flow-row grid-auto-flow: row;
grid-flow-col grid-auto-flow: column;
grid-flow-dense grid-auto-flow: dense;
grid-flow-row-dense grid-auto-flow: row dense;
grid-flow-col-dense grid-auto-flow: column dense;

Basic usage

Controlling grid element placement

Use the grid-flow-{keyword} utilities to control how the auto-placement algorithm works for a grid layout.

Grid Auto Flow - 图1


1. <div class="grid grid-flow-row-dense grid-cols-3 grid-rows-3 ...">
2. <div class="col-span-2">01</div>
3. <div class="col-span-2">02</div>
4. <div>03</div>
5. <div>04</div>
6. <div>05</div>
7. </div>


Applying conditionally

Hover, focus, and other states

Tailwind lets you conditionally apply utility classes in different states using variant modifiers. For example, use hover:grid-flow-row to only apply the grid-flow-row utility on hover.


1. <div class="grid grid-flow-col hover:grid-flow-row">
2. <!-- ... -->
3. </div>

For a complete list of all available state modifiers, check out the Hover, Focus, & Other States documentation.

Breakpoints and media queries

You can also use variant modifiers to target media queries like responsive breakpoints, dark mode, prefers-reduced-motion, and more. For example, use md:grid-flow-row to apply the grid-flow-row utility at only medium screen sizes and above.


1. <div class="grid grid-flow-col md:grid-flow-row">
2. <!-- ... -->
3. </div>

To learn more, check out the documentation on Responsive Design, Dark Mode and other media query modifiers.