The browser resolves it in order: origin and importance first, then cascade layers, then specificity, then document order. Inline styles outrank normal author rules, and an important declaration flips the origin order so an important user or user agent rule can beat an important author rule. Within one layer, specificity counts id, then class, attribute and pseudo class, then element selectors. Ties go to whichever rule comes last.
Why interviewers ask this
CSS bugs at scale are cascade bugs, not syntax bugs. The interviewer is checking whether you can reason about a specificity conflict instead of adding another important flag and moving on. Mentioning cascade layers shows you have kept up with how modern codebases isolate third party styles and utility classes. It also opens the door to how you would structure CSS so these conflicts stop appearing in the first place.
How to structure your answer
- List the resolution order before you talk about specificity numbers.
- Explain specificity as three buckets, not a single score.
- Say where cascade layers sit and why they help.
- Give your rule for when important is acceptable.
Example answer
I think of it as a sequence of tiebreakers. First the browser looks at origin and importance, so an inline style beats a stylesheet rule and an important declaration changes the ordering entirely. Then cascade layers, which is the part people miss: an unlayered rule beats anything in a layer no matter how specific the layered rule is, and later layers beat earlier ones. Only after that does it compare specificity, and that is three buckets, ids then classes and attributes and pseudo classes then element selectors, compared left to right, so a single id beats any number of classes. If everything ties, the last one in document order wins. In practice I use layers to make this boring. I put reset in a first layer, then third party, then components, then utilities last, so a utility class always wins without needing important. The only place I still use important is for a genuinely non negotiable rule, usually something inside a print stylesheet.
Walking into this interview soon? GhostPilot listens to your live call, spots the question the moment it is asked, and puts a structured answer on your screen in real time. Try it on your next mock, or grab a $29 Session Pass, no subscription, for the real thing.
See how it worksFollow-up questions to expect
- What does the where pseudo class do to specificity, and why is it useful?
- How do cascade layers interact with important declarations?
- How would you debug a rule that looks like it should apply but does not?
Related frontend developer questions
Your interviewer will ask their own version of this. Paste your actual job description into the free Question Predictor and get the 20 questions that role is most likely to ask, with what each one is really probing.
Predict my questions