What made a parent selector hard

The objections historically raised against container queries apply equally to a "parent selector": a change to an element's width invalidates a query, which can change the width again, and on around the loop. Containment solved that problem for container queries. The relational selector, officially specified as :has in Selectors Level 4, has traditionally run into related trouble, most notably the requirement for "multiple pass" rendering, which has long been considered too slow to be acceptable.

Brian Kardell frames the constraint in terms of CSS's performance guarantees:

Primarily, even without :has() it’s pretty hard to live up to performance guarantees of CSS, where everything continue to evaluate and render “live” at 60fps. If you think, mathematically, about just how much work is conceptually involved in applying hundreds or thousands of rules as the DOM changes (including as it is parsing), it’s quite a feat as is. Engines have figured out how to optimize this based on clever patterns and observations that avoid the work that is conceptually necessary – and a lot of that is sort of based on these subject invariants that has() would appear to throw to the wind.

Why the spec is encouraging

The existence of a specification is itself encouraging, and more so because Igalia has it in its sights. Some of the performance problems have reportedly either been surmounted or, through testing, found to be negligible enough that the feature remains shippable.

Igalia's track record is relevant here: the team has worked on notable web engine features including CSS grid and container queries, which gives :has a real chance of shipping — though Adrian Bece notes there is still a long way to go. In his Smashing Magazine treatment of the subject, he examines why the relational selector has been one of the most requested features of recent years, how developers currently work around its absence, and the early spec, along with the improvements it should bring to styling workflows once released.

The naming has drawn some commentary. :has follows how jQuery rolled with its own has, but as Adrian pointed out in a tweet, the native selector is considerably more versatile.

A long-running watch

Interest in the selector is not new: it has been tracked closely for about a decade, alongside ongoing efforts to document concrete use cases for a parent selector.