Performance: Grid auto-flow and placement
This affects how the browser places grid items and calculates layout, impacting rendering speed and visual stability.
<div class="grid grid-cols-3 gap-4"> <div class="col-start-1 row-start-1">Item 1</div> <div class="col-start-2 row-start-1">Item 2</div> <div class="col-start-3 row-start-1">Item 3</div> <div class="col-start-1 row-start-2">Item 4</div> </div>
<div class="grid grid-cols-3 grid-flow-row gap-4"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> <div>Item 4</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Auto-flow with implicit placement | Standard DOM nodes | Multiple reflows on content change | Moderate paint cost due to layout shifts | [X] Bad |
| Explicit grid placement with Tailwind classes | Standard DOM nodes | Single reflow on initial layout | Lower paint cost with stable layout | [OK] Good |
grid-flow-row do in a grid container?grid-flow-row sets the grid to place items in rows first, meaning items fill left to right in each row.grid-flow-col sets the grid to fill columns first, placing items top to bottom in each column.grid-auto-flow-col and grid-auto-columns are not valid Tailwind classes for this purpose.<div class="grid grid-cols-3 grid-flow-row-dense gap-2"> <div class="col-span-2">A</div> <div>B</div> <div>C</div> <div>D</div> </div>
grid-flow-row-dense class places items row-wise but tries to fill gaps left by spanning items.<div class="grid grid-flow-col gap-4"> <div>1</div> <div>2</div> <div>3</div> </div>
grid-flow-col places items top to bottom in each column, then next column, but without defining the number of columns or rows, the grid defaults to one implicit column.grid-cols-3 or similar, the grid does not create multiple columns, so items stack vertically in one column.grid-flow-col sets column flow by default (small screens).sm:grid-flow-row-dense changes flow to dense row on screens medium and up.grid-cols-2 for small screens and sm:grid-cols-4 for larger screens set grid size accordingly.Pass the test and this pattern moves unknown