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

All template syntax commands · Svelte and SvelteKit 5 cheatsheet

Was this page helpful?