Performance: Grid gap
LOW IMPACT
Grid gap affects the layout calculation and paint phases by adding spacing between grid items without extra DOM elements.
display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
display: grid; grid-template-columns: repeat(3, 1fr); /* Instead of gap, using margin on grid items */ .grid-item { margin-right: 1rem; margin-bottom: 1rem; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using margin on grid items for spacing | No extra nodes but margin affects layout | Multiple reflows per item | Higher paint cost due to layout thrashing | [X] Bad |
| Using grid gap property | No extra nodes, spacing handled by grid | Single reflow for grid container | Lower paint cost, stable layout | [OK] Good |