Svelte and SvelteKit 5 · Template syntax
Loop over a list
Give each item a key, in parentheses, so Svelte can update the list efficiently.
<ul>
{#each items as item (item.id)}
<li>{item.name}</li>
{:else}
<li>Nothing here</li>
{/each}
</ul>
Official Svelte and SvelteKit 5 documentation
More template syntax commands
- Show content conditionally
- Show an async result
- Bind form inputs
- Handle events
- Toggle classes
- Reusable markup with snippets
All template syntax commands · Svelte and SvelteKit 5 cheatsheet