Performance: Defining grid columns
This affects how the browser calculates layout and paints grid items, impacting page load and rendering speed.
<div class="grid grid-cols-3 gap-4">...</div><div class="grid grid-cols-[repeat(auto-fill,minmax(150px,1fr))] gap-4">...</div>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed grid-cols-3 | Minimal | 1 reflow on load | Low paint cost | [OK] Good |
| grid-cols-[repeat(auto-fill,minmax(150px,1fr))] | Minimal | Multiple reflows on resize | Higher paint cost | [X] Bad |
grid-cols-3 do in a grid container?grid-cols-3 means setting the grid to have 3 columns.grid-rows-{number}, gaps by gap-{size}. So this class only sets columns.grid-cols-{number}.grid-cols-4 matches the correct pattern. Others are invalid or set rows.<div class="grid grid-cols-2 gap-4"> <div>Box 1</div> <div>Box 2</div> <div>Box 3</div> </div>
grid-cols-2 creates 2 columns. gap-4 adds space between grid items.<div class="grid grid-cols-">Content</div>
grid-cols- is incomplete; it needs a number to define how many columns.grid-cols- like grid-cols-3. Without it, the class is invalid.lg: to apply styles on large screens and above.grid-cols-1 for default (small screens) and lg:grid-cols-4 for large screens.Pass the test and this pattern moves unknown