CSS Module 14
Custom properties, nesting, scope and architecture interview questions
Interview questions on custom properties, nesting, scope and architecture: warm-ups, then what each harder question tests and how a good answer starts.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
When does the fallback in var() apply?
-
Mid to senior
What does registering a custom property with @property change?
Answered in the lesson Typed custom properties with @property
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
A design system declares --brand and --link: var(--brand) on :root. A campaign page sets --brand on its .campaign wrapper, but the links inside keep the old colour. Explain why, fix it, and say how you would stop the next derived token from breaking the same way.
- What it tests
- When a var() inside a custom property is replaced, inheritance of computed values, and organising derived tokens so that themes and sections can change them.
- First step
- Find the element where --link is declared. Its var(--brand) is replaced there, on :root, at computed-value time, before anything is inherited, so every descendant inherits the finished colour and not the reference. The campaign's --brand never reaches --link.
- Follow-ups
-
- Why does a button that declares --btn-bg: var(--brand) itself follow the campaign colour?
- What does re-declaring derived tokens on every theme selector cost?
- How would you catch this bug before it ships?
From the lesson Custom properties (CSS variables)
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.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
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
-
Fresher to mid
After a refactor, spacing tokens are bare numbers, such as --space-2: 8, and components write padding: var(--space-2)px. Every component lost its padding, yet DevTools shows no crossed-out declaration. What happened, and how should spacing tokens be stored?
- What it tests
- Token-by-token substitution, invalid at computed-value time against parse-time errors, calc() for adding units, and designing tokens that are hard to misuse.
- First step
- Read the declaration as the browser does after substitution: 8 followed by px is a number and a word, not the length 8px. The declaration contains var(), so it was accepted when the style sheet was parsed and DevTools does not cross it out; it fails at computed-value time and padding takes its initial value, 0.
- Follow-ups
-
- Why does calc(var(--space-2) * 1px) work?
- Should tokens carry their units or be bare numbers?
- How would registering --space-2 with @property change what you see?
From the lesson Custom properties (CSS variables)
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A gradient border driven by --angle turns smoothly in the design prototype, but on the production site it jumps once per turn, and in one browser it disappears. Production also loads a third-party widget. How do you find the cause, and what makes the animation robust?
- What it tests
- How registration fails silently, last-rule-wins and global registration, checking registration in DevTools, and fallbacks for engines without @property.
- First step
- Check whether --angle is registered at all on production: read it with getComputedStyle() on an element that does not set it. A registered property shows its initial value; an empty string means no valid registration, and a jump halfway through each turn is exactly what an untyped custom property does.
- Follow-ups
-
- What could the third-party widget have to do with it?
- Why does the gradient disappear in one browser instead of jumping?
- How would you stop this from happening again?
From the lesson Typed custom properties with @property
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Senior to staff
Your component library exposes --card-radius and --card-accent to the apps that use it, and apps sometimes set them to wrong values, which breaks cards in odd ways. Would you register them with @property? What improves, what gets worse, and how would you roll the change out?
- What it tests
- Typed validation and its trade-offs, choosing inherits for a theming API, initial values as defaults, global names, and a careful rollout across many consuming apps.
- First step
- Separate the two failures. Unregistered, a wrong value breaks the property that uses it: the radius or the colour falls back to its initial value, so the card loses its corners or its accent. Registered, the custom property rejects the value itself and keeps a sensible default, so cards stay usable, but the mistake becomes silent.
- Follow-ups
-
- Should these properties inherit?
- What happens in apps whose users run a browser without @property support?
- How do you keep the silent failure visible to app developers?
From the lesson Typed custom properties with @property
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes