Skip to content
tezvyn:

Explain :is() vs :where() specificity and when to pick :where()

Source: developer.mozilla.orgHardHow cards are made

Explain :is() vs :where() specificity and when to pick :where()

Tests whether you treat specificity as architecture, not just syntax. :where() has zero specificity; :is() adopts the most specific argument's weight. Choose :where() for base resets or utility classes designed to be overridden. Red flag: calling them equal.

What's really being asked

This tests whether you understand specificity as an architectural constraint rather than a trivia fact. Senior engineers building design systems must control the specificity of base styles so that product teams can override them with simple class selectors without resorting to !important or artificially inflated selectors.

The full answer

First, the exact rule: :where() always has zero specificity, while :is() takes on the specificity of the most specific selector in its argument list. Second, the practical implication: grouping selectors with :is() can accidentally create a high-specificity barrier that is hard to override, whereas :where() gives you the grouping convenience without the specificity penalty. Third, a concrete scenario where you would intentionally choose :where(): global reset styles, utility classes, or design system primitives that must remain easy to override. Fourth, mention that both use forgiving selector parsing, so invalid selectors in the list are ignored rather than invalidating the whole rule, though this is a secondary point and not the primary difference.

The mistakes people make

Saying the two are interchangeable or differ only in browser support. Claiming that :where() has lower specificity but not stating it is exactly zero. Giving an example where you choose :where() solely because it is newer or shorter, without mentioning specificity architecture. Failing to mention that :is() specificity is determined by its most specific argument, not an average or sum. Describing the difference in vague terms like one is stronger without quantifying the zero versus most-specific rule.

What usually comes next

How would you use :where() in a CSS reset or normalize stylesheet? If a team complains that utility classes are being beaten by base styles, how would :where() fix that? Can you combine :where() with :is() in the same selector, and what would the resulting specificity be? How does forgiving selector parsing help when using vendor-prefixed or cutting-edge pseudo-classes? When would you actually want the higher specificity of :is()?

A concrete example

Imagine a design system provides a reset for heading margins: :where(h1, h2, h3, h4, h5, h6) { margin-top: 0; }. Because :where() has zero specificity, a product developer can override it later with a single class like .article-title { margin-top: 2rem; } using 0-1-0 specificity. If the system had used :is(h1, h2, h3, h4, h5, h6) instead, the reset would carry 0-0-1 specificity, tying with element selectors and beating some utility classes, forcing developers to fight the cascade.

Interview question

A design system groups element selectors for a global reset. Developers complain that single-class utilities cannot override it. Switching from :is() to :where() fixes this because...

  • a.:is() totals the specificity of all arguments, making grouped resets hard to override
  • b.:where() has zero specificity, while :is() takes on the specificity of its most specific argumentCorrect
  • c.the two pseudo-classes behave identically in the cascade and differ only in browser support
  • d.:where() has lower specificity than :is() but still carries the weight of an element selector
Why?

:where() always has zero specificity, so a single class easily overrides it, whereas :is() inherits the most specific argument's weight, creating a barrier. Option D is tempting because it admits :where() is lower but incorrectly claims it still carries element-level weight rather than zero.

Just read this? Test yourself on what you have been reading.

Read the original → developer.mozilla.org

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on css — each one lists the topics its interview covers.

See open roles