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
- Loop over a list
- Show an async result
- Bind form inputs
- Handle events
- Toggle classes
- Reusable markup with snippets
All template syntax commands · Svelte and SvelteKit 5 cheatsheet