However, for actual CSS, I don't think this is a good idea. You shouldn't need the has() selector if you write your own CSS and HTML.
However, for actual CSS, I don't think this is a good idea. You shouldn't need the has() selector if you write your own CSS and HTML.
Edit; I actually had a use case were I was building an expanding menu, without JavaScript, it involved a ~ and > selector on a checkbox to get that to work. The :has selector would’ve made it straight forward.
Also going back to the roots of CSS, :has() is ideal for semantic markup where you don’t want or need to use excessive class names. Obviously with class heavy frameworks and methodologies that are in vogue :has() is less relevant.
There is more than one way to use CSS.
> Your CSS should describe how the HTML looks
That’s literally what :has() does, based on the structure of the document.
And at any rate, removing classes and IDs as much as possible and just having a page full of semantic tags is generally a goal for a certain school of web development.
div:has(:focus-visible)
for showing the focus state on a parent element. This is otherwise impossible without using JavaScript.So now, instead of adding class to an element to choose how to display those differences of content, I can just use :has() selector. Thus removing even more design concerns from the HTML back into the CSS where it belongs.
But yea you’re right that it’s not going to be really common