Svelte · Junior · Question 29 of 76

How does a component render content passed between its tags in Svelte 5?

<!-- Card.svelte -->
<script>
  let { children } = $props();
</script>

<div class="card">{@render children?.()}</div>

Explanation

<slot> is the Svelte 4 mechanism. The optional call children?.() avoids an error when nothing was passed.

Further reading

Problem with a question

Svelte · Junior · question 29

Test yourself

Take the Svelte · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz