Performance: Padding
MEDIUM IMPACT
Padding affects layout size and can trigger reflows when changed, impacting rendering speed and visual stability.
div { padding: 1.25rem 0.625rem; } /* Using relative units for consistent spacing */div { padding: 20px 10px 20px 10px; } /* Large padding causing layout shift on resize */| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Fixed large padding in px | Minimal | Triggers reflow on resize | Medium paint cost | [!] OK |
| Relative padding in rem/em | Minimal | Single reflow on initial load | Low paint cost | [OK] Good |
| Padding changed dynamically via JS frequently | Multiple DOM writes | Multiple reflows | High paint cost | [X] Bad |