0Pricing
Sveltejs Academy · Lesson

{#if} {#else if} {#else}

Conditionally render markup based on JavaScript expressions.

Conditional Blocks

Svelte conditionals look like Handlebars: {#if}, {:else if}, {:else}, closed with {/if}.

Basic Example

Show one branch or another based on a boolean expression.

{#if loggedIn}
  <p>Welcome back!</p>
{:else}
  <p>Please sign in.</p>
{/if}

All lessons in this course

  1. {#if} {#else if} {#else}
  2. {#each} with Index and Key
  3. {#key} for Forcing Re-render
  4. Nested {#each} and Keyed Updates
← Back to Sveltejs Academy