Performance: Defining grid rows
This affects how the browser calculates layout and paints grid rows, impacting rendering speed and visual stability.
<div class="grid grid-cols-3 grid-rows-2"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> <div>Item 4</div> </div>
<div class="grid grid-cols-3"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> <div>Item 4</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Grid without defined rows | Standard DOM nodes | Multiple reflows on content/layout changes | Higher paint cost due to layout shifts | [X] Bad |
| Grid with defined rows (e.g., grid-rows-2) | Standard DOM nodes | Single reflow on initial layout | Lower paint cost, stable layout | [OK] Good |
grid-rows-3 do in a grid container?grid-rows-3 specifies the number of rows in the grid layout.grid-rows-{number} to define rows.grid-rows-4 matches the correct pattern for 4 rows.<div class="grid grid-rows-[100px_200px_auto] gap-4"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> </div>
grid-rows-[100px_200px_auto] sets explicit heights for each row in order.<div class="grid grid-rows-[100px 200px auto]"> <div>A</div> <div>B</div> <div>C</div> </div>
grid-rows-[...] using underscores. The third row uses 1fr to fill leftover space.150px_300px_1fr. grid-rows-[150px_300px_auto] uses auto which doesn't fill remaining space. grid-rows-[150px_2fr_auto] uses 2fr incorrectly for second row. grid-rows-[150px_150px_1fr] has equal second row height.Pass the test and this pattern moves unknown