Performance: Gap between grid cells
This affects the rendering speed and layout stability by controlling spacing between grid items without extra elements.
<div class="grid grid-cols-3 gap-4"> <div>Item 1</div> <div>Item 2</div> <div>Item 3</div> </div>
<div class="grid grid-cols-3"> <div class="mr-4">Item 1</div> <div class="mr-4">Item 2</div> <div>Item 3</div> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Margin on grid items | No extra nodes | Multiple reflows (per item) | Higher paint cost due to layout shifts | [X] Bad |
| Grid gap property | No extra nodes | Single reflow for container | Lower paint cost, stable layout | [OK] Good |
gap-4 do in a grid layout?gap-4 classgap-4 class in Tailwind adds spacing between grid cells both horizontally and vertically.gap-x-4 or gap-y-4 add space only horizontally or vertically, but gap-4 applies to both directions equally.gap-x-{size} sets horizontal gap and gap-y-{size} sets vertical gap.gap-x-6 gap-y-2 is correct.<div class="grid grid-cols-3 gap-3"> <div>A</div> <div>B</div> <div>C</div> </div>
gap-3 have on the grid cells?gap-3 which adds spacing between all cells horizontally and vertically.gap-4 gap-y-8. What is wrong?gap-4 class sets both horizontal and vertical gaps to 1rem. The following gap-y-8 class overrides only the vertical gap to 2rem, leaving the horizontal gap at 1rem.gap-x-4 for horizontal and gap-y-2 for vertical gaps to set different sizes.Pass the test and this pattern moves unknown