Performance: Why styling options matter
MEDIUM IMPACT
Styling options affect page load speed, rendering performance, and visual stability by influencing CSS size, selector complexity, and reflow frequency.
import styles from './Page.module.css'; export default function Page() { return <div className={styles.container}>Hello World</div>; } /* Page.module.css */ .container { padding: 20px; }
import '../styles/global.css'; export default function Page() { return <div className="container big-padding">Hello World</div>; } /* global.css */ .container { padding: 20px; } .big-padding { padding: 100px; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Global CSS with broad selectors | Low | Multiple on style changes | High due to large repaint areas | [X] Bad |
| CSS Modules with scoped selectors | Low | Single on load | Low due to smaller repaint areas | [OK] Good |
| Inline dynamic styles changing layout | Low | One per interaction | High due to layout thrashing | [X] Bad |
| CSS classes with transitions | Low | None on toggle | Low, handled by compositor | [OK] Good |