:is(), :where() and :has()

:is() and :where()

Both group selectors to avoid repetition. :is() takes the specificity of its most specific argument; :where() always has zero specificity, which makes it ideal for easy-to-override defaults.

/* instead of: article h1, article h2, section h1, section h2 */
:is(article, section) :is(h1, h2) { line-height: 1.2; }

/* zero-specificity reset, easy to override later */
:where(ul, ol) { padding-left: 1.2rem; }

:has(): the Parent Selector

Example

:has() selects an element based on what it contains. Check the box to highlight the whole card:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .card { border: 2px solid #ddd; padding: 12px; border-radius: 8px; font-family: Arial; transition: border-color .2s, background .2s; }
    .card:has(input:checked) { border-color: #04AA6D; background: #e6fcf5; }
    .card:has(img) { display: flex; gap: 10px; align-items: center; }
  </style>
</head>
<body>

<label class="card"><input type="checkbox"> Select this plan</label>
<br>
<div class="card"><img src="https://picsum.photos/id/64/50/50" alt="" width="50" height="50"> A card with an image becomes a row</div>

</body>
</html>

Result