Skip to main content

Composition for Sveltes

Composition in Svelte is the practice of building interfaces from smaller components that pass data and content to each other. Props carry values down, snippets and children pass markup, and special elements such as svelte:head, svelte:window and svelte:element let a component reach outside its own markup or choose a tag dynamically.

Stage: Component Patterns · Part of the Svelte roadmap · Last reviewed 19 November 2026

What to learn in Composition

Composition interview questions

How do snippets differ from slots in Svelte?

Snippets are Svelte 5's replacement for slots. They are named blocks of markup, declared with the snippet syntax, that can take parameters and be passed as props, rendered with the render tag. Slots are the older mechanism and are deprecated.

How does a child component tell its parent something happened?

In Svelte 5 the usual way is a callback prop: the parent passes a function, such as onsave, and the child calls it with any data. Two-way binding with $bindable is also possible but should be used sparingly.

Where Composition fits in the Svelte roadmap

Composition belongs to the Component Patterns stage (intermediate level). Compose and share.

Back to the full Svelte roadmap