what is svelte

what is svelte

June 12, 2020
3 minutes read time

What is Svelte?
Svelte is a front-end technology similar in use to React, Vue, Angular, and the like. However, instead of loading a framework on the client-side, Svelte wires everything up during the build step, meaning it doesn't have to interpret any additional information at runtime. However, it's still in its relative infancy.

When should you use Svelte?

  • If you want to try out a framework that builds into an app, rather one that uses a framework at runtime.
  • If you feel like React, Vue, Angular, etc. might be too "heavy".
  • If you like trying new things.

When should you not use Svelte?

  • If you need an extremely battle-tested, extremely community supported framework.
  • If you don't need interactivity/data binding.

Styling a component:

  p {
    color: purple;
    font-family: "Comic Sans MS", cursive;
    font-size: 2em;


Bound Text Input:

    let name = '';

<input bind:value={name} placeholder="enter your name">
<p>Hello {name || 'stranger'}!</p>

Reactive statement on a button:

    let count = 0;

    $: if (count >= 10) {
        alert(`count is dangerously high!`);
        count = 9;

    function handleClick() {
        count += 1;

<button on:click={handleClick}>
    Clicked {count} {count === 1 ? 'time' : 'times'}

CSS class bindings:

  let current = "foo";

  button {
    display: block;

  .active {
    background-color: #ff3e00;
    color: white;

<button class:active="{current === 'foo'}" on:click="{() => current = 'foo'}">

<button class:active="{current === 'bar'}" on:click="{() => current = 'bar'}">

<button class:active="{current === 'baz'}" on:click="{() => current = 'baz'}">

Built-in animation transitions:

  import { fade, fly } from "svelte/transition";
  let visible = true;

  <input type="checkbox" bind:checked="{visible}" />

{#if visible}
<p in:fly="{{ y: 200, duration: 2000 }}" out:fade>
  Flies in, fades out

Other resources