Skip to content
Tutorials Center
My learning

Topics

CSS Reference ยท Pseudo-elements

The ::slotted() pseudo-element

Reference for the CSS ::slotted() pseudo-element: style elements passed into a shadow DOM slot from inside a web component, with specificity and limits.

The ::slotted() pseudo-element is used inside a shadow tree (a web component's private styles). It selects elements from the page that the user placed into one of the component's <slot> elements, so a component can style the content it receives.

It takes a compound selector as its argument and only matches the top-level nodes assigned to the slot, not their children.

CSS
::slotted(p) {
  margin: 0;
}

Try it

A card that styles its slot

Syntax

CSS
::slotted(<compound-selector>) { }
slot::slotted(.item) { }
Property Value
Applies to Elements assigned to a slot, in the shadow tree stylesheet only
Inherited Slotted elements inherit from the slot, following the flattened tree
Animatable Properties follow their own rules

Values

Argument Description
::slotted(*) Every top-level slotted element.
::slotted(p) Slotted <p> elements.
::slotted(.item) Slotted elements with the class.
::slotted([name="x"]) Slotted elements matching an attribute.

Only a compound selector is allowed: no spaces or combinators inside the parentheses.

Usage notes

  • Only direct slotted nodes. ::slotted(p) matches a slotted paragraph but not a <span> inside it. Style deeper content from the page, or with inherited properties.
  • The page wins. Normal rules in the outer document beat ::slotted() rules from the shadow tree when both set the same property. Treat it as a default look for the component.
  • Text nodes are not matched. Only elements can be selected. Wrap loose text in an element.
  • Default slot content (fallback inside <slot>) is part of the shadow tree and is styled directly.
  • Inside the shadow tree only. Writing ::slotted() in a normal page stylesheet matches nothing.
  • Pairs with :host. Use :host to style the component element itself.

Browser support

Supported in all current browsers.