DevTools Logo

Svelte Playground

Svelte Playground

Write a Svelte component, inspect the generated JavaScript and warnings, and see a live preview.

Runs in your browser
Svelte 4 syntax
Try an example

Svelte source

5 lines

Compiler output

0 errors · 0 warnings

Svelte Playground is a single-component scratchpad. It splits your file into script, template and style blocks, renders a lightweight preview for the supported expression subset, and shows a readable teaching version of the compiled JavaScript alongside a11y and syntax diagnostics. Everything runs locally: no upload, no install and no server round-trip. The bundled syntax targets Svelte 4; Svelte 5 runes are reported explicitly instead of failing silently.

Counter
<script>
  let count = 0;
</script>

<button on:click={() => count += 1}>Count: {count}</button>

The preview renders the button and the compiled pane shows the instance script and fragment update function.

Reactive statement
<script>
  let name = "world";
  $: greeting = "Hello, " + name + "!";
</script>

<h1>{greeting}</h1>

The $: declaration is highlighted in the compiled output so learners can see how Svelte tracks dependencies.

Accessibility check
<a href="#">Click me</a>
<img src="photo.png">

Both lines produce a11y warnings with the rule code and a click-to-fix explanation, without blocking the preview.

Examples

Reactive declaration

Input
$: greeting = "Hello, " + name + "!";
Output
$: greeting = "Hello, " + name + "!"; in the compiled output

Reactive statements are carried into the generated instance code so learners can see the dependency tracking.

Missing alt text

Input
<img src="photo.png">
Output
a11y-image-alt on line 1

Accessibility warnings are informational: the preview still renders, and the message suggests alt="".

Unclosed block

Input
{#if visible}<p>Hello</p>
Output
unclosed-block error: 1 opened, 0 closed

Structural errors stop the output pane and show a line/column banner while keeping your source.

About this tool

Svelte Playground is a browser-only scratchpad for a single Svelte component. It separates script, template and style blocks, renders a preview for the supported expression subset and shows a readable teaching version of the compiled JavaScript next to the source.

Diagnostics are first-class: unclosed {#if} or {#each} blocks, Svelte 5 rune syntax in a Svelte 4 file and common accessibility problems such as href="#" links or images without alt text are reported with a rule code, message and source line.

Compile options (dev mode, immutable mode and injected versus external CSS) change the emitted output immediately. Share links encode the source and options in the URL fragment; nothing is uploaded and no compiler service is contacted.

What this tool does not do

  • Only a single component file is supported; there is no SvelteKit routing, store or multi-file module graph.
  • The preview evaluates a small expression subset (identifiers, literals and basic arithmetic) without eval.
  • Svelte 5 runes are reported as errors because this tool targets Svelte 4 syntax.
  • Compiled JavaScript is a readable teaching sketch rather than the exact output of a pinned compiler release.
  • Nothing is uploaded or persisted on a server; share links depend on the URL fragment.

How to use this tool

  1. Start with a snippet

    Pick Counter, Reactive statement, Each block or another chip to load a working component.

  2. Edit the source

    Type in the Svelte source pane. The output, warnings and preview update on every change.

  3. Inspect the output

    Use the Compiled JS, CSS, Warnings and Preview tabs. Warnings show a rule code and a plain-language fix.

  4. Toggle options

    Switch Dev mode, Immutable or the CSS output mode to compare the generated code.

  5. Share a repro

    Copy share link encodes source and options in the fragment; Restore reads them back.

Use cases

Learn reactivity

Change a $: declaration and watch the compiled output and preview update together.

Check a minimal repro

Paste a failing component, capture the diagnostics and copy a shareable URL.

Teach accessibility

Trigger a11y warnings and discuss the fix without leaving the page.

Compare CSS modes

Toggle injected versus external CSS to see the difference in generated output.

Analyzed component model

FieldMeaning
blocksscript, module script, style and template ranges with start and end lines
compiledJsReadable component skeleton with instance script, reactive declarations and init call
compiledCssVerbatim contents of the style block
previewHtmlTemplate with block markers removed and simple expressions interpolated
issuesErrors and warnings with code, message, line and column

The teaching compiler shows the shape of Svelte output; it is not a byte-identical compiler build.

Common mistakes

Mistake:Pasting Svelte 5 runes into a Svelte 4-focused tool.

Fix:The playground reports $state() explicitly; rewrite with let and $: or use the current Svelte REPL.

Mistake:Thinking the compiled pane is the exact compiler bundle.

Fix:It is a teaching sketch of the generated structure, not a byte-identical compiler artifact.

Mistake:Using href="#" as a placeholder button.

Fix:Use a <button> with an on:click handler; the a11y rule explains why.

Mistake:Expecting imports of svelte/transition to run.

Fix:This lightweight preview does not resolve runtime modules; it analyses and renders the markup subset.

Mistake:Assuming shared links are stored on a server.

Fix:Source and options live entirely in the URL fragment; Restore decodes them locally.

Frequently asked questions

Does it run the real Svelte compiler?

No. This browser-only tool analyses the component locally and emits a readable teaching sketch of the generated JavaScript. It is designed for learning and quick diagnostics, not as a byte-identical replacement for the compiler bundled with your project.

Can I see the compiled JavaScript?

Yes. The Compiled JS tab shows the instance script, reactive declarations and a component skeleton with an init call. The CSS tab shows the style block contents, and the Preview tab renders the template with simple expressions interpolated.

Which Svelte version is used?

The syntax and generated shape target Svelte 4. Svelte 5 runes such as $state() are detected and reported as an explicit error so you know why the snippet does not compile here.

Why does my component warn about accessibility?

Svelte-style a11y checks flag patterns such as a link with href="#", an image without alt text, or a click handler on a non-interactive element. Each warning includes a rule code, the source line and a plain-language fix. Warnings never block the preview.

Is my code uploaded anywhere?

No. Parsing, diagnostics and the preview all run in your tab. Share links encode the source and options in the URL fragment only, so they can be pasted into an issue without a server round-trip.

What can the preview render?

It supports the common template subset: text interpolation, {#if} and {#each} marker removal, string/number/boolean literals and basic arithmetic. Runtime imports such as svelte/transition and complex component composition are outside its scope.

References & standards