Named Slots
Named slots
Section titled “Named slots”A named slot is a <slot> element with a name attribute in the shadow tree, paired with a slot attribute on a light-DOM child. The browser matches them by name and renders each light-DOM child at its corresponding insertion point. Using multiple named slots lets a single component expose several distinct content areas — a common pattern for card, dialog, and layout components.
<my-card> <span slot="header">Card Title</span> <p slot="body">Card body text here.</p></my-card>class MyCard extends HTMLElement { connectedCallback() { const shadow = this.attachShadow({ mode: 'open' }); shadow.innerHTML = ` <style>...</style> <div class="card"> <header><slot name="header">Untitled</slot></header> <section><slot name="body">No body.</slot></section> </div> `; }}customElements.define('my-card', MyCard);Unmatched slot attributes
Section titled “Unmatched slot attributes”Light-DOM children with a slot attribute that does not match any named slot in the shadow tree are silently skipped — they are not rendered anywhere. This means typos in slot names cause invisible content, so double-check your slot names when debugging missing content.
Default and named together
Section titled “Default and named together”An element can have both named slots and a default slot at the same time. Named-slot children are distributed to their matching named slots, while any remaining children without a slot attribute fall through to the default slot. This makes it easy to build components that have structured sections (header, footer) plus a freeform content area.