Svelte and SvelteKit 5 · Template syntax

Show content conditionally

Use {#if} blocks, with {:else if} and {:else} branches.

{#if user}
  <p>Welcome, {user.name}</p>
{:else}
  <p>Please sign in</p>
{/if}

Official Svelte and SvelteKit 5 documentation

More template syntax commands

All template syntax commands · Svelte and SvelteKit 5 cheatsheet

Was this page helpful?