Performance: Role of CSS in web development
CSS affects how fast the page looks styled and how smoothly it responds to user actions.
Jump into concepts and practice - no test required
body, div, p { font-size: 16px; }body { font-size: 16px; } div { font-size: 16px; } p { font-size: 16px; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Repeating styles for many selectors | Low | Low | Low | [!] OK |
| Combining selectors to reduce repetition | Low | Low | Low | [OK] Good |
| Using deep complex selectors | Low | Medium | Medium | [X] Bad |
| Using simple class selectors | Low | Low | Low | [OK] Good |
p, followed by curly braces with styles inside.is inline HTML, not CSS. paragraph { color: blue; } uses wrong selector name. all(p) { color: blue; } is invalid CSS syntax.
<h1> tag be?h1 { color: red; }
h1.special { color: green; }<h1 class='special'>Hello</h1>h1.special is more specific than just h1, so it overrides the color.<h1> has class 'special', so the green color applies.body { font-size 16px; color: black }font-size 16px; misses the colon.