[csswg-drafts] [selectors] Backwards combinators (#12453)

LeaVerou has just created a new issue for https://github.com/w3c/csswg-drafts:

== [selectors] Backwards combinators ==
Combinators that could go "backwards" have been proposed before, but until `:has()` they were rejected on the basis of feasibility. However, now that we have `:has()`, they are merely syntactic sugar:

- Parent: `E < F` as sugar over `F:has(> E)`
- Previous sibling: `E - F` as sugar over `F:has(+ E)`
- Ancestor: `E << F` as sugar over `F:has(E)`

Why add them?
- Improved DX for authors. Inverting existing combinators is much more natural than using a completely different syntax to go in the opposite direction.
- Can be used by UAs for performance optimizations. For example, [expanding IDREF attributes to allow selectors](https://github.com/whatwg/html/issues/10143). Currently, the previous sibling can only be specified as `:has(+ &)`, which seems _extremely_ inefficient.
- As they are more limited, they could be allowed in contexts where `:has()` is not (such restrictions have been discussed in the past for various features)

cc @tabatkins @fantasai 

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/12453 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Sunday, 6 July 2025 19:16:58 UTC