Performance: Global vs scoped style strategies
MEDIUM IMPACT
This affects page load speed and rendering performance by controlling how CSS is applied and how much style recalculation the browser must do.
<style>
button {
background: blue;
color: white;
}
</style>
<!-- Scoped styles apply only to this component's elements --><style>
:global(button) { background: blue; color: white; }
:global(h1) { font-size: 2rem; }
/* Global styles applied to all matching elements */
</style>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global styles | High (many elements matched) | Multiple reflows if styles change | High due to broad repaint | [X] Bad |
| Scoped styles | Low (limited to component DOM) | Single reflow per component | Lower paint cost | [OK] Good |