Motif cards on Mrs. Lastri’s frame: your :has() selector becomes a real rule, each match is numbered with the child or sibling that made it match, and ticking…
Why it matters
:has() replaces the most common JS pattern: "if a child is ticked, invalid or present, restyle its parent". Fewer classList.toggle calls, and the visual state follows the real DOM. Every modern browser supports it.
The key idea
:has() picks the element it tests, not its content
Common mistakes
Nesting :has() inside :has() Not allowed: :has(:has(...)) makes the selector invalid and the browser drops the whole rule. One :has() with a longer selector inside is usually enough.
A :has() selector cast too widebody:has(.x) means one change anywhere may restyle the whole page, so the browser keeps re-checking. Put it on the tightest parent, say .form:has(...).
Thinking :has() adds up its arguments’ specificity The specificity of :has() is that of its most specific argument, not the sum. :has(#x, .y) = (1,0,0). The same as :is() and :not().
Try it in this playground
Open The picked cloths, then tick another card on the page No JS runs on that page. The parent label changes because the browser checks :has(input:checked) again.
Open The field filled in wrong, then fix the email yourself Once the input is valid, .field:has(input:invalid) stops matching and the red goes by itself.
Write your own :has() selector that hits something Say, change input:checked to input:not(:checked) on The picked cloths, or img to p on the picture cards.
See :has() inside :has() rejected See the browser’s own error: the selector is invalid, so the whole rule is dropped.