A web component can keep its structure in shadow DOM while letting consumers supply selected content. A <slot> element marks an insertion point in that structure. Children supplied inside the custom element are projected there; the slot itself does not add visible content. section 8.4
Choose the insertion points the component needs:
- Use <slot></slot> for children without a slot attribute. If there is more than one unnamed slot, only the first receives projected content. section 8.4
- Use <slot name="title"></slot> for a named insertion point. A consumer supplies it with a child such as <span slot="title">Camera</span>; matching children are projected in their original order. section 8.4.2 section 8.4.4
- Put fallback markup between a slot’s tags, as in <slot>No message provided.</slot>. It appears only when that slot receives no matching content. section 8.4.1
A product-details contract
A product-details component can place named title and action slots around an unnamed description slot. Its consumer supplies <span slot="title">USB-C Camera</span>, description text, and <button slot="action">Add to Cart</button>. If no action is supplied, a disabled “Out of stock” button in the slot serves as fallback. The consumer’s child order need not match the template’s layout. section 8.4.2
Projection does not move children into the shadow DOM. The browser renders a flattened tree combining shadow structure with assigned light-DOM content, while the DOM trees remain separate. Slotted content is primarily styled by the document that defines it. For predictable styling, style a slot’s container, expose CSS custom properties, or document styling expectations for consumers. section 8.4.3 section 8.5 section 8.5.2
To react to assignments, listen for slotchange on the slot and inspect assignedNodes() or assignedElements(). The event tracks changes to directly assigned nodes, not edits inside them; assignedElements() excludes text and comments. Tests can check assignment through these methods instead of inferring it from outer HTML. section 8.6.1 section 8.6.2 section 9.7.2
Treat slot names as a public API: name them semantically, document expected content, and provide useful fallbacks. Prefer attributes or properties for content required for the component to function; reserve slots for customization. Keep nested slot chains shallow. section 8.8 section 8.7

