Performance: Global styles
MEDIUM IMPACT
Global styles affect the initial page load and rendering speed by applying CSS rules broadly across the entire app.
<style global>
body {
margin: 0;
font-family: Arial, sans-serif;
color: #333;
}
*, *::before, *::after {
box-sizing: border-box;
}
</style><style global>
body, div, span, p, a, ul, li, h1, h2, h3, h4, h5, h6 {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
color: #333;
}
* {
box-sizing: border-box;
}
/* many complex selectors and overrides */
</style>| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Broad global selectors (e.g., body, div, span, *) | High (matches many nodes) | Multiple reflows on load | High paint cost due to many style changes | [X] Bad |
| Minimal global styles with simple selectors (e.g., body, *, *::before) | Low (matches fewer nodes) | Single reflow on load | Low paint cost | [OK] Good |