where

A pseudo-class that groups selectors with zero specificity. Replaces using :not() to exclude components when base styles for article text beat their classes.

Modern approach

Wrapping .prose in :where() makes everything inside the parentheses count as 0, so :where(.prose) a only has the specificity of a (0-0-1). .btn (0-1-0) is stronger, so buttons get the .btn styles without being excluded.

:where(.prose) a {
  color: #06c;
  text-decoration: underline;
}

.btn {
  background-color: #06c;
  color: #fff;
  text-decoration: none;
}
<div class="prose">
  <p>See the <a href="/guide/">guide</a> for details.</p>
  <a class="btn" href="/contact/">Contact us</a>
</div>

Legacy approach

Giving links in article text a color and underline also hits button links placed inside the article. .prose a (specificity 0-1-1) beats .btn (0-1-0), so buttons were excluded with :not(.btn). Every new component placed inside the article meant another class to exclude.

.prose a:not(.btn) {
  color: #06c;
  text-decoration: underline;
}

.btn {
  background-color: #06c;
  color: #fff;
  text-decoration: none;
}
<div class="prose">
  <p>See the <a href="/guide/">guide</a> for details.</p>
  <a class="btn" href="/contact/">Contact us</a>
</div>

Things to watch when replacing

  • Only what’s inside the parentheses of :where() counts as 0. Selectors outside them, like the a in :where(.prose) a, still count toward specificity as before.
  • Because specificity goes down, other rules that used to lose can start winning. For example, a reset’s a { color: inherit; } has the same specificity (0-0-1) as :where(.prose) a, so whichever comes later wins.
  • Pseudo-elements (such as ::before) can’t go inside the parentheses.

How it differs from :is()

:is() groups selectors in the same way, but takes the specificity of the most specific selector inside its parentheses. When you only want to shorten a list like section h2, article h2, aside h2 without changing specificity, use :is().

:is(section, article, aside) h2 {
  margin-top: 2em;
}
  • Inside :is() and :where(), an unsupported selector doesn’t stop the others from working. In a plain comma-separated selector list, a single unsupported selector makes the whole rule ignored.

Browser Support

  • Chrome

    v88+
    2021-01-19
  • Edge

    v88+
    2021-01-21
  • Safari

    v14+
    2020-09-16
  • Safari (iOS)

    v14+
    2020-09-16
  • Firefox

    v78+
    2020-06-30

Search by feature name or code

e.g. aspect-ratio, :has(), padding-top

Try a different word or a property name.

Could not load search.