pseudo-class

:has() — CSS reference

Matches the anchor when a relative selector finds a match from it. A leading > restricts the relationship to a direct child. Nested has() is invalid; the most specific argument determines specificity.

Formal Syntax & Structure

css syntaxcss
:has(relative-selector-list)

Working Example

Example Snippetcss
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Selector lab</title><style>:where(.sample) { color: rgb(32, 32, 32); }div:has(> strong) { color: rgb(0, 96, 80); }</style></head><body><div id="a" class="sample">A <strong>Important</strong></div><div id="b" class="sample">B <span><strong>Nested</strong></span></div></body></html>
CSS Reference