There are three common ways to apply CSS: external stylesheet, internal style block, and inline style.
Preferred approach
Use external stylesheets for maintainability and caching. Reserve inline styles for exceptional dynamic cases.
Pitfall
Mixing all three approaches randomly leads to override confusion and debugging overhead.
Important interview questions and answers
- Q: Why external CSS first?
A: Better reuse, cacheability, and cleaner separation from markup. - Q: When is inline style acceptable?
A: Small dynamic values generated by scripts when class abstraction is impractical. - Q: Where should stylesheet links live?
A: In documentheadfor early discovery and stable rendering.
Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.