Logical Pseudo-Classes: :is(), :where(), :not() and the :has() Parent Selector
The functional pseudo-classes that take selector lists: :is() for shorter selectors and forgiving lists, :where() for zero specificity, :not() for exclusions and its traps, and :has() for selecting parents and previous siblings, with its limits.
kvi5hnuCode Sprout team member9 min readOn this page
Four pseudo-classes take selectors as arguments: :is(), :where(), :not() and :has(). The first two shorten long selector lists and control specificity. :not() excludes elements. And :has(), the long-awaited "parent selector", selects an element by what it contains or what comes after it, which changes what CSS alone can do.
:is(): matches any selector in a list
:is(A, B, C) matches an element that matches any of the selectors in the list. It factors out repetition:
/* without :is() */
.contact-form input,
.contact-form textarea,
.contact-form select { border: 1px solid #999; }
/* with :is() */
.contact-form :is(input, textarea, select) { border: 1px solid #999; }
The savings grow quickly when several parts vary. Headings inside either articles or asides, at two levels:
:is(article, aside) :is(h2, h3) { font-family: Georgia, serif; }
/* replaces: article h2, article h3, aside h2, aside h3 */
The arguments can be complex selectors with combinators: :is(.card > img, figure img). Pseudo-elements can't be matched inside: in :is(p::before), the forgiving list drops the pseudo-element argument, so it never matches anything.
A forgiving selector list
As article 3 explained, a normal selector list is dropped entirely if one selector in it is invalid. :is() and :where() take a forgiving list: invalid or unsupported selectors are ignored, and the rest still work:
input:is(.has-error, :user-invalid) { border-color: #b3261e; }
A browser that doesn't know :user-invalid still applies the rule to .has-error. (Inside @supports selector(...), the list isn't forgiving, so @supports selector(:is(:foo)) is false, which is what a feature test needs.)
Specificity of :is()
An :is() takes the specificity of its most specific argument, regardless of which argument actually matches the element:
:is(p, #intro) { } /* specificity of an ID, even for elements that match only p */
That makes it easy to raise specificity by accident. Article 15 covers specificity in detail.
A subtle matching rule
Each argument is matched against the whole document, not only the part of the tree to its right. So section :is(.featured p) matches a paragraph inside a section whose .featured ancestor may be outside the section: the .featured part can be any ancestor of the paragraph. When that matters, write the full structure without :is().
:where(): the same, with zero specificity
:where() is identical to :is(), including the forgiving list, except that it always has zero specificity, whatever is inside:
:where(.site-header, #footer) a { color: inherit; } /* specificity of just "a" */
That's its purpose: writing styles that are easy to override. Library authors, resets and base styles use it so that any class-based rule from the site can win without a fight:
/* a reset that never wins against your component styles */
:where(ul, ol)[role="list"] { list-style: none; padding: 0; }
:is() | :where() | |
|---|---|---|
| matches | any argument | any argument |
| forgiving list | yes | yes |
| specificity | its most specific argument | always zero |
| typical use | shortening selectors | defaults that are easy to override |
![Two renders of a numbered list with role="list". When the reset is written (ul, ol)[role="list"] { list-style: none }, a later .steps { list-style: decimal } rule loses and the list has no numbers, because the reset's specificity is 0,1,1. Written with (), the reset weighs 0,1,0, the same as .steps, which comes later and wins, so the numbers 1, 2 and 3 appear](https://code-sprout-content.laxmi.solutions/asset/2026/11/css-is-vs-where-render-6irxnlhed7fbkxb7.png)
The only difference between the panels is the reset's wrapper. With :where(), the component class can override the reset without a fight.
:not(): everything except
:not(X) matches elements that don't match X:
li:not(.sold-out) { } /* items without that class */
a:not([href^="/"]) { } /* links that don't start with / */
input:not([type="checkbox"], [type="radio"]) { width: 100%; } /* a list: neither */
.card:not(:last-child) { margin-bottom: 1rem; }
- It accepts a list, meaning "none of these".
:not(.a, .b)matches the same elements as:not(.a):not(.b), although its specificity is lower: one class instead of two. - It accepts complex selectors, such as
:not(.card > p), and can be nested::not(:not(p))is valid, if pointless. - Its list isn't forgiving. An invalid selector inside
:not()makes the whole rule invalid. That's deliberate: forgiving it would turn "not X" into "not anything", matching everything. - Its specificity is that of its most specific argument, like
:is().:not(#x)counts as an ID. - Pseudo-elements aren't allowed inside.
Negation traps
:not() tests one element, and combinators around it don't mean what they seem to:
div:not(.promo) p { color: #555; }
This reads like "paragraphs that aren't inside a .promo div", but it means "paragraphs inside some div that isn't .promo". In <div class="promo"><div><p> the inner div isn't .promo, so the paragraph matches anyway. Likewise, :not(.promo) p matches almost every paragraph, because <body> and <html> aren't .promo either.
To express "not inside", put the whole relationship inside :not():
p:not(.promo p) { color: #555; } /* paragraphs not anywhere inside .promo */
div:not(.promo) p { text-decoration: underline; } /* misleading */
p:not(.promo p) { color: #2f7d4f; } /* correct */

The first two selectors highlight the paragraph inside .promo too: some ancestor that isn't .promo is always there. Only the third version expresses "not inside".
:has(): select by what an element contains
:has(X) matches an element when X, read relative to that element, matches something. The plain form looks at descendants:
.book-card:has(img) { grid-template-rows: 10rem auto; } /* cards with a cover image */
.book-card:has(> img) { } /* an image as a direct child */
form:has(:user-invalid) .submit { opacity: 0.5; } /* a form with a bad field */
Because the argument is relative, it can start with any combinator:
| Selector | Matches |
|---|---|
a:has(img) | a link containing an image, at any depth |
li:has(> ul) | a list item with a nested list as a direct child |
h2:has(+ p) | an h2 immediately followed by a p |
li:has(~ .selected) | every li before a .selected sibling |
label:has(+ input:required) | a label right before a required input |
So :has() selects parents and ancestors (section:has(h2)), previous siblings (h2:has(+ p)), and whole components by their state (.menu:has(:focus-visible)), all things CSS couldn't do before.

In every panel, the highlighted element is the one before :has(). The argument only decides whether it matches.
.grid { display: flex; gap: 0.75rem; font-family: system-ui, sans-serif; }
.book-card { border: 1px solid #ccc; border-radius: 8px; padding: 0.75rem; width: 11rem; }
.book-card .cover { height: 5rem; background: #e2d4bd; border-radius: 4px; }
.book-card:has(.cover) { border-color: #8a3b12; }
.book-card:not(:has(.cover)) { background: #f7f7f7; }
.book-card:has(.badge) h3::after { content: " ★"; color: #c58b00; }
h3 { font-size: 1rem; margin: 0.5rem 0 0.25rem; }
State without JavaScript
Combined with form states, :has() lets one element's state change styles anywhere above it. A checkbox can switch the whole page into a compact view:
.shop { font-family: system-ui, sans-serif; }
.books li { padding: 0.75rem; border-bottom: 1px solid #ddd; }
.shop:has(#compact:checked) .books li { padding: 0.2rem 0.75rem; font-size: 0.9rem; }
.shop:has(#compact:checked) .blurb { display: none; }
Common patterns:
body:has(dialog:modal) { overflow: hidden; }stops the page scrolling behind an open modal..field:has(input:user-invalid) .hint { color: #b3261e; }styles a whole field group when its input is invalid.ul:has(> li:nth-child(6))styles a list with six or more items, a simpler quantity query.:root:has(#theme-dark:checked) { color-scheme: dark; }switches themes with a form control.
Using form controls for visual state is fine. Don't use hidden checkboxes to fake interactive widgets such as menus: they don't announce themselves correctly to assistive technology. Use real buttons with popover or <details> (article 60).
Limits of :has()
- No nesting:
:has()can't contain another:has().div:has(:has(img))is invalid. - No pseudo-elements inside:
:has(::before)is invalid. - Its list isn't forgiving: one invalid selector inside makes the whole
:has()invalid. Test new selectors separately, or put them inside:is()within:has(). - Specificity is that of its most specific argument, like
:is()and:not().
Feature detection
:has() is in every current browser, but to give older ones a fallback, test it with @supports selector(:has(a)) { ... } (article 6).
Performance
:has() is harder for browsers than other selectors, because a change deep in the tree, such as a class added to one item, can change which ancestors match. Engines have optimized it heavily, and normal uses are fast. Two habits keep it that way:
- Anchor it to a specific element, as in
.book-card:has(img), rather than:has(img)alone orbody :has(...), which forces the browser to check every element. - Prefer short relative selectors, such as
> imgor+ p, over broad ones like:has(*)on large subtrees that change often.
What's current
:is()and:where()are Baseline widely available (since 2023).:not()with lists and complex selectors works in all current browsers.:has()has been Baseline since December 2023, and widely available since June 2026.
Common questions
Is :has() really a parent selector?
It's more general. .card:has(img) selects a card containing an image anywhere inside it, .card:has(> img) one whose direct child is an image, and h2:has(+ p) selects a heading by its next sibling. It selects the element it's attached to, based on a condition relative to it.
When should I use :where() instead of :is()?
When the rule should be easy to override: resets, defaults, library styles, and base styles in a design system. Use :is() when you just want a shorter selector and the specificity of its arguments is fine.
Why does div:not(.promo) p still match paragraphs inside .promo?
Because the paragraph has other ancestors that are divs without .promo. :not() tests a single element, so put the whole condition inside it: p:not(.promo p).
Can I use :has() to check if an element has no children?
:not(:has(*)) matches elements with no child elements, ignoring text and whitespace. :empty requires no text either (article 10).
Is :has() slow?
Not for normal use. Keep it anchored to a specific element and avoid broad patterns on parts of the page that change constantly, and it performs like other selectors.
Summary
:is()matches any selector in its list, shortens repetitive selectors, takes a forgiving list, and has the specificity of its most specific argument.:where()is the same with zero specificity, ideal for defaults that should be easy to override.:not()excludes elements. It takes a list and complex selectors, isn't forgiving, and tests only the element it's attached to, so writep:not(.promo p)for "not inside".:has()selects an element by a relative condition: descendants, children, next or later siblings, and their states.:has()can't be nested, can't contain pseudo-elements, and isn't forgiving.- All four are supported in every current browser.
Practice questions
Rewrite this selector list with :is():
nav a:hover, nav a:focus-visible, footer a:hover, footer a:focus-visible
Answer
:is(nav, footer) a:is(:hover, :focus-visible)
What's the specificity difference between :is(.card, #featured) h2 and :where(.card, #featured) h2?
Answer
:is() takes the specificity of its most specific argument, the ID, so the first selector counts as one ID plus one type. :where() has zero specificity, so the second counts only as the h2 type selector, and almost any other rule for h2 can override it.
Write a selector for list items that come before an item with class current, so a breadcrumb trail can style the steps already taken.
Answer
li:has(~ .current)
It matches each li that has a later sibling with class current.
Why is article:has(img, :hoover) a problem, and how would you fix it?
Answer
:has() takes an unforgiving list, so the invalid :hoover makes the whole selector invalid and the rule is dropped. Remove the typo, or, for a selector that might be unsupported, put the list inside :is(): article:has(:is(img, :new-thing)).
Write a rule that dims the submit button of a form while the form contains a field the user has filled in invalidly.
Answer
form:has(:user-invalid) button[type="submit"] { opacity: 0.5; }
Previous: State Pseudo-Classes: Links, , , and Form States
Next: Pseudo-Elements: ::before, ::after, ::first-line, ::marker, ::selection and More

More in CSS Course
Quiz: CSS Delicate Details
Twenty-five questions on the edge cases that surprise experienced developers: invalid custom properties, shorthands that reset values, layer order with !important, containing blocks, margin collapsing, specificity of :is() and :where(), intrinsic minimum sizes, and more, each checked in Chrome.
Quiz: CSS Interview Questions
Thirty front-end interview questions: cascade, specificity and layers, box model and margin collapsing, stacking contexts, positioning, flexbox and grid, responsive design, custom properties, performance, accessibility, modern selectors and architecture.
Quiz: CSS Course Final Exam
Thirty questions across the whole CSS course: syntax and error handling, selectors, the cascade and layers, values and units, color, the box model, backgrounds, positioning, flexbox, grid, responsive design, typography, generated content, effects, transforms, motion and architecture.
Quiz: CSS Architecture, Tooling and Debugging (CSS Part 17)
Twenty questions on modular CSS and BEM, layering a stylesheet, design tokens and theming, pattern libraries and safe refactoring, preprocessors and build tools, the at-rules reference, and debugging common CSS problems.
Discussion
Sign in to ask a question or share what you learned.