Smarter Selectors with :is(), :where(), and :has()

Write less CSS, control specificity, and finally select what you actually mean

Conceptual CSS artwork for Smarter Selectors with :is(), :where(), and :has().

CSS selectors used to feel pretty straightforward.

Then your project grows a little. You start repeating selectors, fighting specificity, and wishing you could just say what you actually mean instead of working around what CSS allows.

That is where :is(), :where(), and :has() come in.

They are not just “new pseudo-classes.” Together, they change how you think about writing selectors in the first place.

Why selectors start to feel limiting

Most of the time, CSS selectors work exactly the way you expect. You target an element, maybe add a class or two, and move on.

The friction shows up when things get more complex.

You want to style multiple variations of the same thing, but you end up repeating selectors. You want to keep specificity low, but a small change suddenly overrides something it should not. You want to style something based on its children or surroundings, and realize CSS cannot quite express that cleanly.

None of these are huge problems on their own—but together, they add up to selectors that feel more like workarounds than intent.

What these selectors actually give you

Each of these pseudo-classes solves a slightly different problem, but they all push in the same direction: letting you write selectors that match how you think about your UI.

:is() helps you group things together without repeating yourself. :where() does the same thing, but without increasing specificity. And :has() lets you select something based on what is inside it.

On their own, each one is useful. Together, they give you much more control over how selectors behave—both in terms of readability and how they interact in the cascade.

Grouping selectors with :is()

:is() is the easiest place to start because it solves a very familiar annoyance: repeating selectors.

Without it, you might end up writing something like this:

h1, h2, h3 {
  margin-bottom: 0.5em;
}

That works—but it does not scale well when selectors get more complex.

With :is(), you can group those options in a way that stays readable even as things grow.

:is(h1, h2, h3) {
  margin-bottom: 0.5em;
}

The real benefit shows up when the rest of the selector is doing more work.

.article :is(h1, h2, h3) {
  color: var(--heading);
}

Same result, but easier to extend and maintain.

One important detail: :is() takes on the specificity of the most specific selector inside it. That is usually what you want—but it is something to be aware of.

Keeping specificity under control with :where()

:where() looks almost identical to :is(), but it behaves very differently in one key way.

It always has zero specificity.

That makes it incredibly useful for writing styles that should be easy to override later.

:where(h1, h2, h3) {
  margin-bottom: 0.5em;
}

At first glance, this looks the same as :is(). The difference is what happens when something else tries to override it.

Because :where() contributes no specificity, almost any other selector can take priority without needing tricks or escalation.

This is especially useful in things like base styles or design system layers, where you want sensible defaults without making them hard to override.

Think of :where() as “grouping, but polite about it.”

Selecting based on context with :has()

:has() is where things get interesting.

It lets you select an element based on what is inside it—or what comes after it. That might not sound dramatic at first, but it unlocks patterns that were either impossible or awkward before.

.card:has(img) {
  padding-top: 0;
}

This reads almost like plain language: “select cards that have an image.”

You can also use it for things like form states:

form:has(input:focus) {
  outline: 2px solid var(--accent);
}

Instead of styling the input directly, you are reacting at the parent level.

This is something CSS historically struggled with, and it changes how you think about structuring styles.

The mental model (how these fit together)

It is tempting to think of these as three separate features, but they work best when you see how they complement each other.

:is() is about reducing repetition. :where() is about controlling specificity. :has() is about expressing relationships.

Put another way:

:is() simplifies what you write
:where() simplifies how it behaves
:has() expands what is possible

Once you start combining them, selectors begin to feel less like constraints and more like a language you can actually work with.

Using them together

The real payoff comes when you combine these patterns.

For example, you might want flexible heading styles that are easy to override:

.article :where(:is(h1, h2, h3)) {
  margin-bottom: 0.5em;
}

This keeps the selector readable while ensuring it does not create unnecessary specificity.

Or you might combine grouping with contextual logic:

.card:has(:is(img, video)) {
  padding: 0;
}

Now the component adapts based on what it contains, without extra classes or JavaScript.

This is where selectors start to feel expressive instead of restrictive.

What to watch for

The biggest thing to keep in mind is that these features change how specificity behaves—but they do not remove it entirely.

:is() still inherits specificity from its most specific argument, and :has() can create selectors that are more powerful than you expect if you are not careful.

It is also worth remembering that :has() is doing more work under the hood. While browser support is strong, you should still be thoughtful about how often and where you use it.

Rule of thumb:
Use :is() to simplify, :where() to soften, and :has() to react.

Can you use these today?

Yes, in most modern browsers.

If you are supporting older environments, :is() and :where() are generally safer bets, while :has() may need a fallback or progressive enhancement strategy.

The good news is that these features tend to enhance code readability even when used conservatively.

Quick answers

Is :is() just a shortcut?

It is a shortcut, but also a readability improvement—especially for more complex selectors.

Why not always use :where()?

Because sometimes you do want specificity. :where() is best when you intentionally want styles to be easy to override.

Is :has() a parent selector?

It is often described that way, but it is more accurate to think of it as a relational selector. It lets you match based on context, not just hierarchy.

Want to go deeper?

These selectors are part of a broader shift in CSS toward more expressive, flexible logic. As layouts and components become more dynamic, being able to describe relationships directly in CSS becomes more valuable.

Once you start using them, you will notice how many selectors used to feel like workarounds—and how much cleaner they can be when they actually match your intent.