:has()

A CSS pseudo-class that matches an element if something inside it, or after it, matches the given selector, such as .card:has(img).

In more detail

It works like the long-requested parent selector: style a form field that has an invalid input or a card that contains an image without adding classes from JavaScript. Its specificity is that of its most specific argument.

Example

.field:has(input:checked) { border-color: green; }

Related terms

Taught in

References