Favorites

:has-slotted CSS Pseudo Class

:has-slotted
CSS Pseudo ClassThis pseudo class is supported in some modern browsers, but not all.
Updated 22nd November 2026

The :has-slotted pseudo-class matches a slot element when content has been assigned to it.

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.

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

<info-card>
<span slot="title">Card with a footer</span>
<span slot="footer">This footer is slotted, so its slot gets a green border.</span>
</info-card>

<info-card>
<span slot="title">Card without a footer</span>
</info-card>

<script>
customElements.define('info-card', class extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' }).innerHTML = `
<style>
:host { display: block; margin: 12px 0; padding: 12px; border: 2px solid #ccc; border-radius: 8px; font-family: system-ui, sans-serif; width: 320px; }
slot[name="title"] { display: block; font-weight: bold; }
slot[name="footer"]:has-slotted { display: block; margin-top: 10px; padding-top: 8px; border-top: 3px solid seagreen; }
</style>
<slot name="title"></slot>
<slot name="footer"></slot>`;
}
});
</script>
/* The :has-slotted rule lives in the component's shadow root (see the script).
It adds a top border only when content is assigned to the footer slot. */
body {
background: #f8f9fa;
}
Open in editor

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.

This pseudo class is supported in some modern browsers, but not all.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported

Looks like you're using an ad blocker, and that's fine! Ads help keep CSS Portal's generators and references free, so if the site's useful to you, visit our Support page to see other ways to help.