CSS Specificity & Inheritance vs CSS :has() Relational Selector
:has() adopts the highest specificity of its relative selector list instead of summing combinators.
Structured Comparison Matrix
| Dimension | CSS Specificity & Inheritance | CSS :has() Relational Selector |
|---|---|---|
| Mental Model | Cascade resolves Origin, @layer, (A,B,C) specificity, and source order; inherited properties propagate down only when no rule matches. | :has() matches an element based on its descendants or following siblings, eliminating JS parent-class toggling. |
| Maturity & Domain | Baseline · Widely · CSS & Layout Chrome 88+ · Firefox 78+ · Safari 14+ | Baseline · Newly · CSS & Layout Chrome 105+ · Firefox 121+ · Safari 15.4+ |
| Prerequisites | Foundational primitive | |
| When Not to Use | When not to use #id selectors in CSS: Never style with #id selectors in reusable components; reserve #id for DOM anchors and ARIA labelledby targets. | When not to use :has(): Avoid :has() on :root for high-frequency hover/scroll states; scope it to small local components like .field or .card. |
Engine Mechanics & Trade-Offs
Style engine sorts matched declarations by Origin/Importance -> @layer -> (A,B,C) -> Order, then copies inherited properties from parent ComputedStyle.
Key Pitfalls: :is() specificity surprise: :is(#header, .nav) a gives all matches (even .nav a) the #header specificity of (1, 0, 1). Form control inheritance: <button> and <input> have user-agent font and color rules, blocking <body> inheritance unless inherit is set.
Engines attach :has() invalidation flags to ancestors/siblings so DOM mutations only re-evaluate affected subjects instead of scanning the whole tree.
Key Pitfalls: :root:has(...) over-invalidation: Attaching :has() to :root or body with broad selectors like :has(*:hover) triggers wide style recalculations on pointer moves. Nesting :has(:has(...)): Nested :has() is disallowed by the spec and silently ignored.