b2KIT

Svelte Component Playground

Write and preview Svelte components with reactive declarations, stores, and live rendering.

Tested tool guide Tested browser tools Checked August 16, 2026

What Svelte Component Playground does, with a checked example

A browser sandbox for writing Svelte components: type the component's script, markup, and styles into the editor and a preview pane renders the result, updating as you edit. The code is compiled with the Svelte compiler inside the page, so reactive declarations, stores, and event handlers behave as they would in a real app, and nothing you type is uploaded anywhere. The most common stumble is the dollar sign: store values must be read as `{$count}`, while `{count}` renders the store object itself.

Worked example

A concrete input and expected output from the current implementation.

Input

<script>
  import { writable } from 'svelte/store';
  const count = writable(0);
  const add = () => count.update(n => n + 1);
  $: doubled = $count * 2;
</script>

<button onclick={add}>Add one</button>
<p>{$count} -> {doubled}</p>

Expected output

Renders a button labeled Add one with a paragraph reading `0 -> 0`. Each click calls `count.update(n => n + 1)`, raising the store value by 1, and the reactive declaration recomputes `doubled` before the next paint, so after one click the paragraph reads `1 -> 2` and after two clicks `2 -> 4`.

The compiler tracks that `doubled` references `$count`, so every store update re-runs the declaration before rendering, and the paragraph always shows the current store value and its double. The figures follow directly: 0*2=0, then 1*2=2, then 2*2=4.

How the result is produced

1

Compile and render loop

Each edit recompiles the component with the Svelte compiler and the preview is rebuilt from the compiled output, so what you see is a real component instance: reactive declarations, stores, and event handlers run as they would in a built app. Compilation happens in the browser, so the source never leaves the page. Code that does not compile has no runnable form, so the preview updates only for valid Svelte.

2

Reactive declarations and stores

`$:` declarations re-run only when a variable they reference is reassigned; the compiler detects those references statically, so `$: doubled = count * 2` tracks `count`, while a declaration that mutates an unreferenced variable does not re-run for that mutation. Store values are read with the `$` prefix, which subscribes the component to the store; `writable().set()` and `.update()` notify subscribers and the markup re-renders with the new value.

Good uses

  • Prototype a component in isolation - a button, a form field, a filterable list - and settle its markup, styles, and state before moving it into your project.
  • Debug a display that will not update: paste the component, then click or type in the preview to see which assignments actually trigger the reactive declarations.
  • Validate store patterns - shared writable state, derived values, custom stores - and confirm `$` auto-subscription behavior before wiring the store into a multi-component app.

Limits and checks

  • Editing restarts the component. The preview is rebuilt on every change, so runtime state (a counter you clicked, text you typed) resets to its initial value whenever the code changes. Copy anything you need before editing.
  • Reactivity is assignment-driven and `$:` dependencies are static. Reassigning a variable triggers the declarations that reference it; in-place mutation (`items.push(x)`) does not, and a declaration never re-runs for state it does not reference. If something looks stale, suspect the tracking rule, not the compiler.
  • The `$` prefix works only inside a component instance. `{$count}` in markup or a reactive declaration subscribes, but `$count` is invalid in module-level code, where you must call `get(count)` from `svelte/store` instead. Snippets written for older Svelte versions may also behave differently under current ones.

Common questions

The preview shows `[object Object]` where my value should be. What went wrong?

You are rendering the store object, not its value. `{count}` prints the store; `{$count}` subscribes to it and prints the current value. The `$` prefix is required in markup and reactive declarations, and it works only inside a component instance - in module-level code, import `get` from `svelte/store` and call `get(count)`.

Will a component that works here behave the same in my project?

Mostly, but the playground compiles one component in isolation. Imports from your own modules will not resolve, so anything the component needs must be defined inside it - `svelte/store` is available for stores - and only the component's own `<style>` applies, so results can differ until your project's global styles and surrounding context are in place.

References and verification

The example and behavioral notes were checked against the browser implementation. Standards and primary references below define the relevant format, formula, or platform behavior.

Related Tools