Performance: Performance considerations
This affects how fast the page loads and how smoothly it responds to user actions by influencing rendering speed and layout stability.
Jump into concepts and practice - no test required
.highlight { color: red; } /* specific class selector applied only where needed */
body * { color: red; } /* very broad selector applying to all elements */| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Broad universal selectors | High (all elements matched) | Many reflows if styles change | High paint cost | [X] Bad |
| Specific class selectors | Low (only targeted elements) | Minimal reflows | Low paint cost | [OK] Good |
.class instead of complex selectors like div ul li a:hover?.class match elements directly, making style application faster.@import, which slows loading. * { box-sizing: border-box; } div p span { font-size: 1rem; } uses universal selector * and deep selectors, which are slower.<link> tags by a single large CSS file?body { font-family: Arial; }
div p span { color: blue; }div p span is deep and requires multiple element checks..highlight reduces matching steps and speeds rendering.div p span is slow; use a class selector instead. -> Option B