0Pricing
Sveltejs Academy · Lesson

Named Slots with slot="name"

Define multiple insertion points in a component using named slots.

Why Named Slots

Components often need multiple insertion points: a header, a body, and a footer for example.

Defining Named Slots

Add a name attribute to the slot element in the child.

<!-- Layout.svelte -->
<header><slot name="header" /></header>
<main><slot /></main>
<footer><slot name="footer" /></footer>

All lessons in this course

  1. Default Slots for Content Projection
  2. Named Slots with slot="name"
  3. Slot Fallback Content
  4. Checking Slot Content with $$slots
← Back to Sveltejs Academy