Performance: Margin
MEDIUM IMPACT
Margin affects layout calculation and can trigger reflows when changed, impacting page responsiveness and visual stability.
element.style.margin = '10px';
element.style.marginTop = '10px'; element.style.marginBottom = '10px'; element.style.marginLeft = '10px'; element.style.marginRight = '10px';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Setting margins individually multiple times | Multiple style changes | Multiple reflows (one per change) | Higher paint cost due to repeated layout | [X] Bad |
| Setting margin shorthand once | Single style change | Single reflow | Lower paint cost | [OK] Good |