Skip to main content

Svelte Playground

Write Svelte components and see them live in a sandboxed preview, with compiler warnings, extra files and a zip download.

<script>
import Greeting from './Greeting.svelte';

let count = $state(0);
let doubled = $derived(count * 2);
let fruits = $state(['Apple', 'Banana', 'Cherry']);
</script>

<main>
<Greeting name="Svelte" />
<button onclick={() => count++}>Clicked {count} times (double: {doubled})</button>
<ul>
{#each fruits as fruit (fruit)}
<li>{fruit}</li>
{/each}
</ul>
<button onclick={() => fruits.push('Fruit ' + (fruits.length + 1))}>Add a fruit</button>
</main>

<style>
main { font-family: system-ui, sans-serif; max-width: 28rem; margin: 2rem auto; padding: 1.5rem; background: #f8fafc; border-radius: 12px; }
button { padding: 0.4rem 0.9rem; font-size: 1rem; cursor: pointer; margin: 0.25rem 0; }
</style>

PreviewReady in 175 ms
Warnings and console

Compiler warnings, console.log messages and errors appear here.

Shortcuts: Ctrl+Enter run · / search (use ⌘ on Mac)

Free Online Svelte Playground

Try Svelte components live. Write a component in App.svelte, and the preview shows it as you type, with the compiler's warnings and your console messages under it. Add more components, download the project as one zip, and nothing you write is uploaded. Use it to try a Svelte 5 idea, check how runes behave or share a small component without creating a project.

How to use the Svelte playground

  1. Edit App.svelte. A component has a <script> block, markup and an optional <style> block.
  2. Watch the preview update. Compiler warnings (many are accessibility tips), console.log messages and errors appear under it.
  3. Press + to add a component such as Greeting.svelte and use it with import Greeting from './Greeting.svelte'.
  4. Keep shared state in a file that ends in .svelte.js and import it wherever you need it.
  5. Open the ⋯ menu and choose Download all files (.zip) to take the project with you.

What is and is not included

You get Svelte 5 with runes ($state, $derived, $props), each blocks, if blocks, events and scoped styles. Packages need Add packages (downloaded from esm.sh only when you press Add); a router and SvelteKit are not available. For plain pages without a framework use the HTML/CSS/JS Playground, and to check your markup try the HTML Beautifier.

Worked example

The sample is a counter, a list and a small child component. The top of App.svelte:

<script>
  import Greeting from './Greeting.svelte';

  let count = $state(0);
  let doubled = $derived(count * 2);
  let fruits = $state(['Apple', 'Banana', 'Cherry']);
</script>

<main>
  <Greeting name="Svelte" />
  <button onclick={() => count++}>Clicked {count} times (double: {doubled})</button>
  <ul>
    {#each fruits as fruit (fruit)}
      <li>{fruit}</li>
    {/each}
  </ul>
  <button onclick={() => fruits.push('Fruit ' + (fruits.length + 1))}>Add a fruit</button>
</main>

Result: a card with the heading Hello, Svelte! (from Greeting.svelte), a button that counts clicks and shows the doubled value, and a fruit list you can add to.

Common mistakes

  • Writing Svelte 4 style code such as export let name or on:click: this playground uses Svelte 5, so use $props() and onclick.
  • Leaving an {#if} or {#each} block unclosed: the compiler error names the file and line.
  • Importing a package before adding it: press Add packages first.
  • Ignoring accessibility warnings: they point at real problems for keyboard and screen reader users.

Frequently asked questions

Which version of Svelte is this?
Svelte 5, with runes such as $state, $derived and $props. The version is fixed so a project behaves the same every time you open it.
What are the warnings under the preview?
They come from the Svelte compiler. Many are accessibility advice, for example an image without alt text or a click on an element a keyboard cannot reach. Each warning names the file and line. Switch off "Accessibility warnings" to hide that kind.
How do I use another component?
Press + to add a file such as Greeting.svelte, then import it in App.svelte with import Greeting from './Greeting.svelte' and use it as <Greeting name="Ada" />.
Can I share state between components?
Yes. Add a file that ends in .svelte.js, such as counter.svelte.js, and export a $state object from it. Any component can import it.
Can I import a package or use SvelteKit?
You can import "svelte" (stores, motion, transitions), the files in your project (folders work), and packages you add. Press Add packages, type a name such as lodash or zustand@4, and press Add. The package is downloaded from esm.sh at that moment (your code is not sent, only the package name), pinned to the exact version, listed with its size, and saved with your project and its zip as package.json. Nothing is downloaded before you press Add. There is no router or SvelteKit.
Is my code uploaded?
No. The components are compiled in your browser and shown in a sandboxed preview that has no network access unless you switch the internet option on.
How is this different from the Svelte REPL?
It is a smaller tool for quick experiments that runs privately in your browser with no account, and it keeps your files as a project you can save, share by link or download as one zip. It has no packages or router.

Related tools

More Playground

View all Playground tools →