Slots let you put content inside a component from outside. The default slot is the main place where you add this content.
Slot basics (default slot) in Svelte
<slot></slot>
The <slot> tag marks where the outside content will appear.
If no content is given, the slot can show default content inside <slot> like <slot>Default text</slot>.
<slot></slot>
<slot>Default content here</slot>
<div class="wrapper"> <slot></slot> </div>
The Box component uses a default slot with fallback text. In App.svelte, the first <Box> has custom content, so it shows that. The second <Box> has no content, so it shows the default fallback text.
<!-- Box.svelte --> <div class="box"> <slot>Default box content</slot> </div> <style> .box { padding: 1rem; border: 2px solid #007acc; border-radius: 0.5rem; background-color: #e0f0ff; } </style> <!-- App.svelte --> <script> import Box from './Box.svelte'; </script> <Box> <p>This is custom content inside the box.</p> </Box> <Box></Box>
Slots help keep components flexible and reusable by letting you insert any content.
Default slot content only shows if no content is passed inside the component.
You can style the slot container to control how inserted content looks.
Slots let you pass content into components from outside.
The default slot is the main place where this content goes.
If no content is given, default slot content shows instead.