Default Slot vs. Named Slots
What you'll learn: How unnamed (default) slots capture all unmatched content while named slots enable precise, targeted content projection in Web Components.
When working with slots in Shadow DOM, you have two fundamental projection mechanisms: the default slot and named slots.
The Default Slot
A default slot is an unnamed <slot> element that acts as a catch-all. Any content in the Light DOM that doesn't match a named slot automatically flows into the default slot. Think of it as the "everything else" bucket.
<!-- Shadow DOM template -->
<template>
<div class="wrapper">
<slot></slot> <!-- Default slot: catches unmatched content -->
</div>
</template>
Named Slots
Named slots use the name attribute to create explicit projection targets. Content in the Light DOM uses the slot attribute to declare which named slot it belongs to.
<!-- Shadow DOM template -->
<template>
<header><slot name="title"></slot></header>
<main><slot></slot></main> <!-- Default slot -->
<footer><slot name="actions"></slot></footer>
</template>
<!-- Light DOM usage -->
<my-card>
<h2 slot="title">Card Title</h2>
<p>This goes to the default slot</p>
<button slot="actions">OK</button>
</my-card>
How They Work Together
The default slot only receives content that has no slot attribute. Content with a slot attribute goes to its matching named slot. If no matching named slot exists, that content won't render at all—it's like sending a letter to a non-existent address.
This combination gives you precise control: use named slots for structured, predictable content sections (headers, footers, actions) and the default slot for freeform body content.
Key Takeaway: Default slots capture any unslotted Light DOM content automatically, while named slots require explicit slot attributes for targeted projection—use both together to create flexible, well-structured component APIs.