:has-slotted CSS Pseudo Class
The :has-slotted pseudo-class matches a slot element when content has been assigned to it.
Description
The :has-slotted pseudo-class matches a slot element in a shadow tree when content has been assigned to it, meaning the light DOM of the shadow host provides at least one node for that slot. When nothing is slotted and the slot shows its fallback content (or nothing), it does not match.
Component authors can use it to change the layout of a component depending on whether an optional part has been provided, for example adding spacing or a border only when a footer slot is filled:
slot[name="footer"]:has-slotted {
display: block;
border-top: 1px solid #ddd;
padding-top: 8px;
}
It is only useful inside a shadow root stylesheet, because <slot> elements live in shadow trees. Note that any assigned node counts, including a text node that only contains whitespace. Use it together with ::slotted(), which styles the slotted elements themselves, and :host, which styles the shadow host.
Syntax
:has-slotted {
/* ... */
}Example
Browser Support
The following information will show you the current browser support for the CSS :has-slotted pseudo class. Hover over a browser icon to see the version that first introduced support for this CSS pseudo class.
Desktop





Tablets & Mobile





