Performance: Scoped styles by default
This affects rendering speed and visual stability by limiting CSS scope to components, reducing style recalculations and layout shifts.
<style>
button {
color: red;
}
</style>
<script>
// component code
</script>
<button>Click me</button><style>
:global(.button) { color: red; }
</style>
<script>
// component code
</script>
<button class="button">Click me</button>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global CSS styles | Affects all matching elements in DOM | Multiple reflows if styles change globally | High paint cost due to broad style recalculation | [X] Bad |
| Scoped styles by default | Affects only component subtree | Single reflow limited to component | Lower paint cost due to isolated style recalculation | [OK] Good |
<script>
let color = 'blue';
</script>
<style>
p { color: red; }
</style>
<p>Hello</p><style global>
h1 { font-size: 3rem; }
</style>Pass the test and this pattern moves unknown