Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

In CSS, :where() lets you match elements without adding selector specificity. Its own specificity is always zero, and the selectors inside it do not add any either. That makes it useful for baseline styles and selector filters that should remain easy to override.

What zero specificity means in CSS

Specificity is one factor the cascade uses to choose between declarations that apply to the same element. A selector wrapped in :where() can still match elements, and declarations attached to it still participate in the cascade. “Zero” describes only the specificity contribution: :where() and everything inside its parentheses contribute none.

For example, a:where(:not(:hover)) matches links that are not being hovered, but the selector’s specificity remains zero. The condition still filters which links are matched; it simply does not make the rule harder to override. The W3C Selectors Level 4 specification describes this as a way to introduce selector filters while keeping their associated declarations easy to override.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How `:where()` differs from `:is()`

:where() and :is() provide the same matching functionality, but they treat specificity differently. :where() always contributes zero. By contrast, :is(), :not(), and :has() take the specificity of the most specific selector in their argument list.

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
Selector How it matches Specificity contribution Practical fit
:where() Matches according to its selector argument Always zero, including the argument Flexible baseline rules that should be simple to override
:is() Same matching functionality as :where() The most specific selector in its argument list Grouping alternatives when their specificity should count

Consider :where(nav, footer) a versus :is(nav, footer) a. Both can match links inside a navigation or footer element. With :where(), the wrapper and its argument add no specificity; with :is(), specificity comes from the most specific argument, here the type selector nav or footer. The choice is not about whether the condition works, but whether that condition should increase the selector’s weight.

Why use a selector that is easy to override?

When writing reusable styles, you may want a rule to establish a sensible default without making later component, page, or user styles fight a highly specific selector. :where() allows a selector to express structural context or exclusions while keeping specificity low. This is particularly helpful for broad defaults, reset-like rules, or filters that describe where a style applies rather than how forcefully it should win.

The W3C specification illustrates the distinction with a:not(:hover) and a:where(:not(:hover)). The first selector’s specificity can prevent a later nav a rule from taking effect. Wrapping the condition in :where() removes that specificity contribution, allowing the navigation rule to override it when the rest of the cascade permits.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How specificity fits into the full cascade

Zero specificity does not guarantee that another declaration wins. The cascade resolves competing declarations using more than specificity. The current W3C CSS Cascading and Inheritance Level 5 specification puts origin and importance first, then cascade layers and specificity, followed by scope proximity and order of appearance. A rule’s placement in those earlier stages can outweigh a specificity advantage.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Use :where() to control one part of that process: selector specificity. If a declaration still wins unexpectedly, inspect its origin, !important status, layer, scope, and source order as well as its selector. Lowering specificity is not a substitute for understanding those other cascade criteria.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.