CSS :where() Pseudo-Class

Beginner
6 min read
Updated: Nov 2026
3 examples
Live preview

Definition and Usage

The :where() pseudo-class accepts a forgiving selector list and matches an element if it matches any listed selector. Unlike :is(), the entire :where() pseudo-class always has zero specificity.

Baseline · Widely available.

Use it for defaults that should remain easy to override. The rest of the selector outside :where() still contributes specificity.

CSS Syntax

syntax.css
:where(<forgiving-selector-list>){ … }

Selector Forms

FormDescriptionTry it
:where(h1, h2, h3)Group headings with zero specificityTry it
:where(article, aside) pShare a descendant ruleTry it
.card :where(a, button)Keep only .card specificityTry it
:where(#app, .page)IDs inside still contribute zeroTry it

How to Use :where()

  1. Choose the element or scope you want to match.
  2. Write the selector using :where(<forgiving-selector-list>).
  3. Add declarations that communicate the state or grouping clearly.
  4. Test the rule with matching and non-matching markup.
PieceRequired?Role
Base selectorOptionalLimits which elements are candidates
:where()YesApplies this selector's matching behavior
Declaration blockYesDefines the styles for matching elements

Live Preview

Use the controls in the editable examples to observe when :where() matches.

:where() preview

Rule: :where(h1, h2, h3)

The grouped heading default is easy for any class selector to override.

Open live editor

CSS Examples

Each example isolates one practical :where() pattern.

Example 1 — Low-Specificity Headings

The grouped heading default is easy for any class selector to override.

CSS
<style>
  :where(h1, h2, h3) {
    margin-block: 0 0.75rem;
  }
</style>

<h1>Title</h1><h2>Section</h2><p>Text</p>
Try It Yourself

How It Works

  1. The browser evaluates :where(h1, h2, h3) against the document.
  2. Only elements satisfying that selector receive the declarations.
  3. The rule changes the visible state without changing the HTML structure.
  4. Open the editor to test the selector with different markup.

Example 2 — Content Defaults

Both content regions share a paragraph default without extra specificity from article or aside.

CSS
<style>
  :where(article, aside) p {
    line-height: 1.7;
  }
</style>

<article><p>Article text</p></article><aside><p>Aside text</p></aside>
Try It Yourself

How It Works

  1. The browser evaluates :where(article, aside) p against the document.
  2. Only elements satisfying that selector receive the declarations.
  3. The rule changes the visible state without changing the HTML structure.
  4. Open the editor to test the selector with different markup.

Example 3 — Component Controls

Only .card contributes specificity, so utility classes can still win cleanly.

CSS
<style>
  .card :where(a, button) {
    color: #0f766e;
  }
</style>

<div class="card"><a href="#read">Read</a><button>Save</button></div>
Try It Yourself

How It Works

  1. The browser evaluates .card :where(a, button) against the document.
  2. Only elements satisfying that selector receive the declarations.
  3. The rule changes the visible state without changing the HTML structure.
  4. Open the editor to test the selector with different markup.

Edge Cases & Pitfalls

Check browser behavior, specificity, and accessibility before shipping.

specificity

Know what contributes weight

:where() contributes zero specificity, but selectors outside it still count.

support

Test target browsers

Use a sensible fallback when older browser support matters.

scope

Keep the selector intentional

Add a base selector or component scope when a page-wide match would be too broad.

Browser Support

:where() is a browser CSS selector; server runtimes do not evaluate it.

✓ Baseline · Widely available

:where()

Chrome 88+, Edge 88+, Firefox 78+, Safari 14+.

96% Modern browsers
Google Chrome Supported
Full support
Mozilla Firefox Supported
Full support
Apple Safari Supported
Full support
Microsoft Edge Supported
Full support
Opera Supported
Full support
Samsung Internet Supported
Full support
:where() Widely supported

Bottom line: Safe for modern production sites. Test the interaction and cascade in the browsers your audience uses.

Key Takeaways

  • Purpose: accepts a forgiving selector list and matches an element if it matches any listed selector. Unlike :is(), the entire :where() pseudo-class always has zero specificity.
  • Syntax: :where(<forgiving-selector-list>)
  • Practice: keep selectors scoped and easy to override.
  • Testing: verify both matching and non-matching states.

One line: Use it for defaults that should remain easy to override. The rest of the selector outside :where() still contributes specificity.

Frequently Asked Questions

It matches any selector in its argument list, like :is(), while contributing zero specificity.
It lets defaults, resets, and component baselines be overridden without !important or increasingly complex selectors.
No. Only :where() and its arguments contribute zero. Selectors outside it still count normally.
:where() always has zero specificity. :is() takes the specificity of its most specific argument.
Yes. Its forgiving selector list can keep valid alternatives when another argument is unsupported.
Yes. It still matches by ID, but that ID contributes zero specificity.

Next: :nth-child() Pseudo-Class

Continue through the CSS tutorial reference.

:nth-child() Pseudo-Class tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful