:has-slotted CSS pseudo-classThe :has-slotted CSS pseudo-class matches when the content of a <slot> element is not empty or not using the default value (see Using templates and slots for more information).
Note: Even a single whitespace text node is sufficient to make :has-slotted apply.
This only works when used inside CSS placed within a shadow DOM.
/* Selects the content of a <slot> element that has content that is not default */
:has-slotted {
color: green;
}
/* Selects the content of a <slot> element that has no content or default */
:not(:has-slotted) {
color: red;
}:has-slotted {
/* ... */
}This example has two <slot> elements, one of which has been assigned some content and the other has not.
<p>
<template shadowrootmode="open">
<style>
:has-slotted {
color: rebeccapurple;
}
</style>
<slot name="one">Placeholder 1</slot>
<slot name="two">Placeholder 2</slot>
</template>
<span slot="one">Slotted content</span>
</p>The <slot> element that has been assigned content matched the :has-slotted pseudo-class and has the color value of rebeccapurple applied.
<template> element<slot> element::slotted