Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

CSS Module 3

The cascade, specificity and layers interview questions

Interview questions on the cascade, specificity and layers: warm-ups, then what each harder question tests and how a good answer starts.

6 questions: 2 warm-ups and 4 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher to mid

    What steps does the cascade use to decide which declaration wins?

    Answered in the lesson The cascade: which declaration wins

  2. Fresher to mid

    What is the difference between initial, unset and revert?

    Answered in the lesson Inheritance, global keywords and computed values

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A product card has the hidden attribute but still shows on the page, and DevTools shows display: flex on it. Explain why the browser allows this, then fix it in two ways and say which one you would ship in a design system.

    What it tests
    Cascade origins: a normal user-agent declaration against a normal author one, and choosing between a global !important reset and scoped selectors or layers.
    First step
    Find where each display value comes from. The browser's [hidden] { display: none } is a normal user-agent declaration and the site's .card { display: flex } a normal author one, so the card's rule wins on origin before specificity is compared. Any site rule that sets display on the element defeats the attribute.
    Follow-ups

    From the lesson The cascade: which declaration wins

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    A ten-year-old stylesheet has 140 !important declarations, and every new fix adds another. How do you remove them without visual regressions, and which ones would you keep?

    What it tests
    Treating !important as a move to another cascade level, the escalation it causes, layers and specificity as replacements, and a measured refactoring process.
    First step
    Take an inventory before changing anything: group the 140 by why they exist, such as beating a vendor's selector, beating an ID, utilities and state classes, because each group has a different replacement. Then record a baseline of screenshots or computed styles, so that every removal can be checked.
    Follow-ups

    From the lesson The cascade: which declaration wins

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  3. Fresher to mid

    After a redesign set body { font-size: 16px; line-height: 1.5em; }, two-line headings overlap and footnotes look double-spaced. Explain the cause with numbers, give the fix, and say what 150% or 24px would do instead.

    What it tests
    Inheritance of computed values, numbers against lengths for line-height, and reasoning with concrete sizes.
    First step
    Work out what each element inherits. 1.5em on the 16px body computes to 24px, a length, and every descendant inherits 24px, so a 32px heading gets lines 0.75 times its font size and 12px footnotes get lines twice theirs.
    Follow-ups

    From the lesson Inheritance, global keywords and computed values

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 2 minutes
  4. Mid to senior

    You ship an embeddable widget that must look the same on any host page. How do you protect it from inherited and host styles, and what do all: initial, all: unset and all: revert each leave unprotected?

    What it tests
    Inheritance, the CSS-wide keywords and the all shorthand, the limits of isolation in one document, and when shadow DOM or an iframe is the better tool.
    First step
    Separate the two threats: inherited text properties flowing into the widget, and host selectors that match the widget's own elements. all: initial on the widget's root stops the first. Only a stronger cascade position or a shadow root protects against the second.
    Follow-ups

    From the lesson Inheritance, global keywords and computed values

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All CSS interview questions · The CSS track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.