Pseudo-elements style virtual parts of an element such as generated content or typographic fragments.
Frequent pseudo-elements
::beforeand::after::first-lineand::first-letter::selection(browser support caveats apply)
Pitfall
Generated content in ::before/::after is not always reliable for essential information.
Important interview questions and answers
- Q: Why are pseudo-elements useful?
A: Add decorative UI without extra DOM nodes. - Q: Single colon vs double colon?
A: Double-colon is modern syntax for pseudo-elements (single still often supported for legacy). - Q: Can pseudo-element content be interactive?
A: Not as robustly as real DOM elements; avoid for critical controls.
Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.