CSS optimization improves render speed and long-term maintainability, not just file size.
Optimization levers
- Remove dead/unused selectors.
- Split critical vs non-critical styles where needed.
- Minify and compress assets for production.
- Avoid expensive layout thrash patterns in JS-driven style updates.
Production checklist
- Audit bundle size and unused CSS regularly.
- Prefer predictable component classes over global wildcard styles.
- Profile paint/layout in DevTools for heavy pages.
Important interview questions and answers
- Q: Why can “small CSS file” still be slow?
A: Complex selectors, layout thrash, and rendering patterns can dominate performance. - Q: What is critical CSS?
A: Above-the-fold styles delivered early to speed first meaningful rendering. - Q: How to reduce regressions while optimizing?
A: Track metrics and use visual regression checks on key pages.
Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.