Live Examples
Real interactive components rendered inside the docs.
A real, running component
The button below is a real Svelte component running as part of this app. It is not a screenshot, and not a sandboxed iframe. Click it, then open the source:
Single source of truth
The rendered component and the source panel above both come from one file, counter.svelte. It is imported twice: once as a component (rendered) and once
as ?source (highlighted at build time by the docsmith() plugin from svelte-docsmith/vite), so the demo and its code can never drift.
Examples that can't rot
The example in your docs is the same component your users import. When the component changes, the rendered demo and its shown source both change with it, so it can never decay into a screenshot of something that used to work.
See Writing pages for the import pattern to copy.
Coding agents see the same code. In a page’s agent markdown, which feeds llms-full.txt and the .md pages, each LiveExample is
written out as its source file in a svelte code block.
Props playground
Pass a props import as controls and the example
grows a panel of controls, one for each prop whose type allows it. The children snippet then receives the current values, so you decide where they
go:
variant href external <Badge>…</Badge>
The controls come from each prop’s TypeScript type:
| Prop type | Control |
|---|---|
boolean | a switch |
| a union of string or number literals | buttons for up to four choices, a select beyond |
string | a text field |
number | a number field |
| anything else (snippets, callbacks, …) | no control |
A prop starts at its default when that default is a literal like 'primary', false or 3. A prop without a literal default can be left unset, so the
component applies its own fallback. @deprecated props get no control.
Use args to start somewhere else, or to fill a required prop that has no
default. A prop set in args still gets its control, and Reset returns to
these values:
Under the controls, a usage line such as <Badge variant="success" external>…</Badge> shows the props that differ from their defaults, in the order the component
declares them, ready to copy.
Experimental
controls and args are outside the 1.0 stability promise for now. A control
doesn’t follow changes the component makes to a $bindable() prop itself.
API reference
source string ?source
import of the same file.controls ExtractedProps import props from './badge.svelte?props'): shows a
control for each prop whose type allows one, and passes the current
values to children.Fields
name required string FileTree.typeParameters required string[] ['T'].since string @since, from its `<!--props required ExtractedProp[] Fields
name required string type string 'a' | 'b'. Absent when the props are untyped.default string 'default'.required required boolean bindable required boolean $bindable().deprecated string @deprecated: the tag's text as inline HTML, or ''.description string control PropControl Fields
kind: 'boolean'kind required 'boolean' kind: 'text'kind required 'text' kind: 'number'kind required 'number' kind: 'options'kind required 'options' options required (string | number)[] literalDefault stringnumberboolean 'a', false, -1).since string @since text: the release the prop first appeared in.fields ExtractedFieldGroup[] Fields
label string fields required ExtractedField[] Fields
name required string type string default string @default tag's text.required required boolean deprecated string @deprecated: the tag's text as inline HTML, or ''.description string since string fields ExtractedFieldGroup[] inherited required InheritedAttributes[] Fields
kind required 'element''type' element: native attributes of an HTML element (label is the tag name).
type: every prop of some other type (label is that type, as written).label required string args PlaygroundValues children required Snippet<[PlaygroundValues]> controls it receives the current
values: {#snippet children(props)}<Badge {...props} />{/snippet}.