Default and Named Snippets
Provide fallback snippets and name multiple snippet slots in a component.
Default and Named Snippets is a free Sveltejs Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Sveltejs Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Default Snippet
Content placed inside a component's tags becomes the default snippet, accessible via children.
<Card>
<p>Inside the card</p>
</Card>In the Component
Render the default content with the children prop.
let { children } = $props();
<div class="card">
{@render children()}
</div>Named Snippets
Pass multiple snippets by name as props.
<Card>
{#snippet header()}<h2>Title</h2>{/snippet}
{#snippet body()}<p>Text</p>{/snippet}
</Card>Receive Named
Declare each named snippet as a prop.
let { header, body } = $props();
{@render header()}
{@render body()}Fallbacks
Default fallback content using normal conditionals.
{#if header}{@render header()}{:else}<h2>Default</h2>{/if}Type Safety
Type each snippet param explicitly for IDE support.
Replacing Named Slots
Snippets replace the named slots pattern from Svelte 4, with more power.
Default Content
Snippets do not have built-in fallback; use {#if} for that.
Composition Patterns
Combine default and named snippets for headless component designs.
Migration Tip
When migrating, convert each named slot to a named snippet prop.
TS Inference
Svelte 5 generates Snippet types automatically from your component's props.
Quick Check
What replaces named slots in Svelte 5?
Recap
Default content uses the children snippet; named snippets are explicit props rendered with @render.
Frequently asked questions
Is the “Default and Named Snippets” lesson free?
Yes — the full text of “Default and Named Snippets” is free to read here on the web, and the Sveltejs Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Sveltejs Academy course, upgrade to CoddyKit PRO.
What will I learn in “Default and Named Snippets”?
Provide fallback snippets and name multiple snippet slots in a component. You practise Sveltejs Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Sveltejs Academy?
No prior experience is required. Sveltejs Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Default and Named Snippets” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Sveltejs Academy lesson?
Yes. Every Sveltejs Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- $props() for Typed Props
- {#snippet} and {@render}
- Passing Snippets as Props
- Default and Named Snippets