Skip to content

Svelte Foundations & Mental Model

Svelte is a compiler. It reads your components at build time and generates small, imperative JavaScript that surgically updates the DOM — there is no virtual DOM and no framework runtime diffing your UI on every change. The “framework” mostly disappears into the output.

Every Svelte feature — runes, snippets, scoped styles, transitions — is a consequence of that: because Svelte compiles your code, it can turn count++ into exactly the DOM update that one change requires, and ship almost nothing else.

LessonWhat you’ll learn
Why Svelte, the compilerThe compile model, no virtual DOM, and tiny bundles
The component anatomyThe .svelte file: script, markup, and scoped styles
Runes & reactivityHow runes drive compiler-generated reactivity (Svelte 5)
Template syntaxInterpolation, {#if}/{#each}/{#await}, and rendering

Two ideas explain almost everything Svelte does:

flowchart TB
  compile["Compiler: analyze components at build time"] --> gen["Generate surgical DOM updates
(no virtual DOM)"]
  runes["Runes: mark what is reactive
($state, $derived, $effect)"] --> gen
  gen --> small["Tiny, fast output"]
The two ideas everything builds on
  • Because Svelte is a compiler, it knows at build time exactly which pieces of the DOM depend on which state — so it writes precise update code instead of shipping a diffing runtime.
  • Because reactivity is declared with runes, the compiler can trace the dependency graph statically and update only what changed, wherever it lives.

Hold those two and Svelte stops looking like magic and starts looking like a very good code generator.

What is Svelte, fundamentally?
How does Svelte update the DOM when state changes?
What do runes do?