Svelte: Compiler-First UI Framework with Runes
GitHub Repo
MIT
November 17, 2026 at 01:41 PM
0 views

Svelte: Compiler-First UI Framework with Runes

@sveltejsProject Author

What Svelte is

Svelte is a UI framework that does most of its work at build time. The repository README describes it as "a compiler that takes your declarative components and converts them into efficient JavaScript that surgically updates the DOM", and the documentation overview says it turns components "written in HTML, CSS and JavaScript" into "lean, tightly optimized JavaScript". There is no virtual DOM diff at runtime: each component compiles to a function that creates its DOM nodes once and then updates exactly the text nodes and attributes that depend on changed state.

The overview positions it for "anything on the web, from standalone components to ambitious full stack apps", with the second half handled by SvelteKit, the companion application framework maintained by the same team in a separate repository. The Svelte package itself covers components, reactivity, transitions and animations, server-side rendering to strings, hydration and compilation to custom elements. Routing, data loading and deployment adapters are SvelteKit's job; the FAQ calls SvelteKit "the official routing library" and compares it to Next.js for React and Nuxt.js for Vue.

The sveltejs/svelte repository is a monorepo whose main package lives in packages/svelte, with the documentation sources under documentation/docs. The project is MIT-licensed, and the README says its development is "made possible entirely by fantastic volunteers", with funding through Open Collective. The current major line is Svelte 5, first published to npm on 19 October 2024; its changelog entry lists "a more granular reactivity system with runes", snippets and event attributes, "native TypeScript support" and "backwards compatibility with the previous syntax".

How it works: the compiler and runes

Components as compiled functions

A component lives in a .svelte file made of three optional parts: an instance <script>, markup, and a <style> block. The .svelte files page says the instance script "runs when a component instance is created", a <script module> block runs once per module, and CSS in <style> "will be scoped to that component". TypeScript is enabled with lang="ts" on the script tag. In Svelte 5 components are no longer classes: the migration guide says they "are functions and should be instantiated differently", using mount or hydrate in the browser and render from svelte/server on the server.

Runes

Reactivity is declared with runes, which the docs define as "symbols that you use in .svelte and .svelte.js/.svelte.ts files to control the Svelte compiler". They look like function calls with a $ prefix, but the docs stress that they are keywords: they are not imported, cannot be passed around as values and "are only valid in certain positions". The core set is:

  • $state creates reactive state. A plain value stays a plain value ("count is just a number, rather than an object or a function"), while arrays and simple objects become deeply reactive proxies, so todos[0].done = true or array.push() trigger granular updates. $state.raw skips the proxy for large data that is only ever reassigned.
  • $derived and $derived.by declare values computed from other state. Anything read synchronously inside is a dependency; the derived is marked dirty on change and recalculated when next read. Since 5.25 a derived can be temporarily overridden by assignment, which the docs suggest for optimistic UI.
  • $effect runs side effects after mount and after state changes, batched in a microtask. The docs call it "something of an escape hatch" and say effects "only run in the browser, not during server-side rendering".
  • $props and $bindable receive component inputs through destructuring, with fallback values, renaming and rest props, and mark which props a parent may bind to.

Runes also work in .svelte.js and .svelte.ts modules, which "behave like any other .js or .ts module, except that you can use runes", so shared reactive logic can live outside components. Classes can use $state in fields; the compiler turns those into getter/setter pairs backed by private fields, which the docs note makes them non-enumerable.

Legacy mode and runes mode

Svelte 5 still accepts Svelte 3/4 syntax (export let, $: statements, on:click, slots). The legacy overview distinguishes "legacy mode" from "runes mode": a component enters runes mode by using runes or by setting the runes: true compiler option, and from then on legacy features are unavailable in that component. Legacy and runes components can be mixed in one app, which is how the migration guide expects most teams to upgrade.

Key features

  • Compile-time output per component. The compiler emits a module per component that imports helpers from svelte/internal/client or svelte/internal/server; the hands-on section below shows what that looks like.
  • Fine-grained updates. Template expressions compile into individual effects that set one text node or attribute, so a state change touches only the DOM that reads it.
  • Scoped CSS by default. Styles get a component-specific class. The FAQ explains that unused selectors are removed with a warning and cannot be kept; styling markup the compiler cannot see requires :global(...).
  • Event attributes. Svelte 5 uses onclick={handler} instead of on:click; the migration guide notes that event modifiers do not apply to attributes and that onevent attributes are delegated.
  • Snippets instead of slots. Content passed between component tags becomes a children snippet prop rendered with {@render children()}; children is therefore a reserved prop name.
  • Reactive built-ins. svelte/reactivity provides reactive versions of Set, Map, Date and URL.
  • Attachments. {@attach ...}, available since 5.29, runs a function in an effect when an element is mounted and can return a cleanup function.
  • Server rendering and hydration. render from svelte/server returns head and body strings; the migration guide says components "are always hydratable now". Recent changelog entries add a hydratable API and a csp option for render.
  • Custom elements. The customElement: true compiler option plus <svelte:options customElement="my-element" /> produces a web component, with the host element available through the $host rune.
  • Async work in progress. The changelog lists await in components behind the experimental.async compiler option (5.36), experimental async SSR (5.39) and an experimental fork API (5.42), so parts of the async story are still flagged as experimental.
  • Migration tooling. The migration guide's script, npx sv migrate svelte-5, converts let to $state, on:click to onclick, slots to snippets and new Component(...) to mount(...); the VS Code extension and the online playground offer a per-component migrate command.

Getting started

The getting-started page recommends SvelteKit, "the official application framework from the Svelte team and powered by Vite", and creates a project with the sv CLI:

npx sv create myapp
cd myapp
npm install
npm run dev

Without SvelteKit, the same page suggests using Svelte directly with Vite through vite-plugin-svelte: run npm create vite@latest and pick the svelte option, after which npm run build writes HTML, JS and CSS into dist. That setup usually needs a separate routing library. Plugins for other bundlers exist, "but we recommend Vite". The FAQ lists community HMR plugins for Rollup and webpack. Code can be type-checked from the command line with npx sv check, and the team maintains a VS Code extension.

A minimal runes component from the $state page:

<script>
	let count = $state(0);
</script>

<button onclick={() => count++}>
	clicks: {count}
</button>

Server rendering in Svelte 5 passes the component to a function instead of calling a method on it, as the migration guide shows:

import { render } from 'svelte/server';
import App from './App.svelte';

followed by render(App, { props: { message: 'hello' }}), which returns html and head. The package declares "node": ">=18" in engines, and the migration guide says Svelte 5 needs a modern browser because it relies on Proxy and ResizeObserver.

Hands-on: compiling and rendering Svelte 5.57.3 on Node 22

All of the following ran on 17 November 2026 on a 2 vCPU x86_64 VM with Ubuntu 24.04.5 LTS, Node.js 22.23.4 and npm 10.9.9, in an empty directory created with npm init -y. No bundler, Vite plugin or SvelteKit was involved: components were compiled with the package's own compile function from svelte/compiler and rendered with render from svelte/server.

Install footprint

MeasureResult
npm i svelte@latest resolved to5.57.3 (VERSION export from svelte/compiler also reported 5.57.3)
Packages added (npm's report)19, audit found 0 vulnerabilities
Direct runtime dependencies in package.json15 (acorn, @sveltejs/acorn-typescript, magic-string, esrap, zimmerframe, devalue, clsx, aria-query, axobject-query and others)
Install wall time, first run2.27 s
node_modules, du -sh (disk usage)8.2 MB
node_modules, du -sb (apparent size)5,236,375 bytes
node_modules/svelte alone, du -sh4.0 MB
Registry unpackedSize for 5.57.32,947,315 bytes in 388 files
Bundled CommonJS compiler, compiler/index.js874,362 bytes

Much of the install is compile-time tooling (the parser, source-map libraries and the ARIA data used for accessibility warnings) that a bundler normally keeps out of the browser bundle; only what the compiled output imports from svelte/internal/* ships to users.

Compiling one runes component for client and server

The test component, Counter.svelte, takes label and start props through $props() with fallback values, holds count in $state(start), computes doubled with $derived(count * 2), increments on an onclick handler, and has a one-rule <style> block. It was compiled with compile(source, { filename, generate }).

Outputgenerate: 'client'generate: 'server'
JS output size906 bytes414 bytes
CSS output size46 bytes46 bytes
Importssvelte/internal/disclose-version and * as $ from 'svelte/internal/client'* as $ from 'svelte/internal/server'
metadata.runestruetrue
Helpers used$.prop, $.state, $.proxy, $.derived, $.get/$.set, $.from_html, $.template_effect, $.set_text, $.delegated/$.delegate$.derived, $.escape, plus $$renderer.push() with a template string
Warningsstate_referenced_locallystate_referenced_locally
First compile in a fresh process50.4 ms7.9 ms
Warm compile, median of 20 (min-max)1.90 ms (1.15-5.53)1.69 ms (1.30-5.93)

The two outputs are structurally different programs. The client version clones a static HTML template (<button class="svelte-xo0eto"> </button> <p> </p>), walks to the two text nodes once, and wraps both set_text calls in a single template_effect; the click listener is attached through event delegation. The server version contains no reactivity at all beyond a derived wrapper: state becomes a plain let, and markup is one template string with every interpolation passed through $.escape. That split is why the server output is less than half the size.

The warning was a useful catch. Its full text was "This reference only captures the initial value of start. Did you mean to reference it inside a closure instead?", pointing at $state(start) on line 3. Seeding local state from a prop is what the component intended here, but the warning makes the one-time copy explicit: a parent that later changes start will not reset count.

Server rendering

CallObserved result
render(Counter, { props: { label: 'Clicks', start: 3 } }), .body<!--[--><button class="svelte-xo0eto">Clicks: 3</button> <p>3 doubled is 6</p><!--]-->
Same call, .headempty string
.htmlidentical to .body
Compiled with css: 'injected', render(Counter, { props: {} }), .head<style id="svelte-xo0eto">button.svelte-xo0eto {font-size:1.25em;}</style>
Same, .bodyfallback props applied: Count: 0 and 0 doubled is 0

The <!--[--> and <!--]--> comments are hydration markers. As the migration guide says, CSS is not returned by default; it only appeared in head once the component was compiled with css: 'injected'. Because render returns plain strings, any Node HTTP server, Express included, can send the result, although hydration in the browser then needs a client build of the same component.

Svelte 4 syntax in a Svelte 5 compiler

Legacy.svelte used export let name, a plain let count = 0, a $: doubled = count * 2 statement and an on:click directive.

Input and optionsResult
Legacy component, default options, clientCompiled, 763 bytes, metadata.runes false, no warnings; adds an import of svelte/internal/flags/legacy
Legacy component, default options, serverCompiled, 347 bytes, no warnings; render with name: 'Svelte' gave <button>Hello Svelte: 0 / 0</button>
Legacy component, runes: falseSame as default: compiled, no warnings
Legacy component, runes: trueError legacy_export_invalid: "Cannot use export let in runes mode — use $props() instead" (line 2, column 1)
export let plus $state in one component, default optionsSame legacy_export_invalid error: using one rune switched the whole component to runes mode
on:click in a runes componentCompiled with warning event_directive_deprecated: "Using on:click to listen to the click event is deprecated. Use the event attribute onclick instead"
The runes Counter.svelte forced to runes: falseCompiled with no error or warning (1,141 bytes), but $props, $state and $derived were treated as auto-subscriptions to stores named props, state and derived; server rendering then threw ReferenceError: props is not defined

The last row is the trap worth remembering: forcing runes: false globally (for example in a bundler config during a gradual migration) does not reject runes, it reinterprets them with Svelte 4's $store syntax, and the failure only shows up at runtime.

Compiler errors for invalid rune usage

InputObserved result
const s = $state; in a componentError rune_missing_parentheses: "Cannot use rune without parentheses" (line 2, column 11)
$props() inside a function in store.svelte.js (via compileModule)Error props_invalid_placement: "$props() can only be used at the top level of components as a variable declaration initializer"
export let c = $state(0) plus a function that reassigns c, in shared.svelte.jsError state_invalid_export: "Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties"
A factory function using $state in counter.svelte.jsCompiled, 225 bytes, importing svelte/internal/client
let count = $state(0) in a plain .js file run with node, with and without import 'svelte'No compiler involved; Node threw ReferenceError: $state is not defined
let d = $derived(c++)Compiled with no error or warning; server render printed 0. The client-side behaviour was not tested

The error messages name the rule and, for warnings, carry a svelte.dev/e/ link. The plain-JS case is the one most likely to confuse newcomers: runes only exist where the compiler runs, so a file must be named .svelte.js or .svelte.ts (and go through the build) to use them. The $derived(c++) row did not match the $derived page's statement that Svelte "will disallow state changes" inside derived expressions at compile time; on this version that check, if present, is not a compile error.

How Svelte compares

None of the frameworks below has its own page here, so they are unlinked. Facts come from each project's README and npm registry entry on 17 November 2026; the Svelte FAQ's own comparison is limited to SvelteKit being similar to Next.js and Nuxt.js.

Project (npm latest)How UI updates happen, per its READMEComponent syntaxRuntime dependencies on npmLicence
Svelte 5.57.3Compiler output "surgically updates the DOM"; runes for fine-grained state.svelte files: HTML superset with script and scoped style15 (mostly compiler tooling)MIT
React 19.3.1React "will efficiently update and render just the right components when your data changes"JavaScript components, usually JSX ("JSX is not required")0 for react (rendering via react-dom)MIT
Vue 3.5.45README only points to the documentation at vuejs.orgNot described in the README5MIT
Solid 2.0.0 (solid-js)"Instead of a Virtual DOM, it compiles templates to real DOM nodes and updates them with fine-grained reactivity"JSX with signals (createSignal); the component function runs once3MIT

Solid is the closest in mechanism: both compile templates ahead of time and both run a component's setup code once, with reactivity tracked per expression. The visible difference is syntax. Solid keeps JSX and exposes state as getter functions (count()), while Svelte uses its own file format and lets count read and write like an ordinary variable, which only works because the compiler rewrites it to $.get/$.set, as the client output above shows. React's README describes a component-based library that re-renders the components affected by a change and stresses gradual adoption; its React Native path is one Svelte does not match, since the Svelte FAQ says Svelte Native is not currently supported in Svelte 5 and points to Tauri, Capacitor or Symbiote Native instead. Choosing among them is usually decided by ecosystem, hiring and existing code rather than by the rendering model alone.

On the tooling side, Svelte is not a build tool. The docs recommend Vite (directly or through SvelteKit), testing guidance in the FAQ mentions Vitest with jsdom for component tests and Playwright or Cypress for browser-based component and end-to-end tests, and for desktop or mobile shells the FAQ points SvelteKit single-page apps at Tauri or Capacitor.

Limits and when not to use it

  • A compiler is mandatory. Runes, scoped CSS and .svelte files only exist after compilation. Dropping a script tag into a page, as React and many libraries allow, is not the path here, and plain .js files cannot use runes (the test above produced $state is not defined).
  • Two dialects in one major version. Svelte 5 accepts both Svelte 4 syntax and runes, which eases upgrades but means tutorials, libraries and answers online may target either. A single rune flips a component into runes mode, and forcing runes: false silently turns runes into store subscriptions.
  • Migration is not fully automatic. The migration guide says the script does not convert createEventDispatcher or beforeUpdate/afterUpdate, may emit run from svelte/legacy as a stopgap for $: statements, and replaces event modifiers with legacy helper functions that should be removed later. Many smaller breaking changes are listed too, from whitespace handling to stricter HTML structure and non-deterministic CSS hash positions.
  • Modern browsers only. Proxies and ResizeObserver are required, and the IE-friendly legacy compiler output no longer exists.
  • Routing and data loading are elsewhere. Using Svelte without SvelteKit means picking a router and an SSR setup yourself; the getting-started page notes that a Vite-only project usually needs a routing library.
  • Native mobile is limited. The FAQ says a custom renderer API has been worked on but "is not yet merged", and Svelte Native, available for Svelte 4, does not support Svelte 5.
  • Some features are still experimental. await in components, async SSR and the fork API are marked experimental in the changelog, and the changelog's long list of 5.57.x hydration and async fixes shows that area is still moving.
  • Unused CSS cannot be kept. The FAQ is explicit that the compiler removes selectors it cannot match, so styling content from {@html ...} or child components needs :global(...).
  • Effects are an escape hatch. The $effect page warns against synchronising state in effects, a pattern that people coming from $: or React's useEffect often reach for.

Recent releases

Svelte 5 ships frequent minor releases. According to the npm registry, 5.25.0 (21 March 2025) added overridable deriveds, 5.29.0 (14 May 2025) introduced attachments, and 5.36.0 (14 July 2025) added await in components behind experimental.async. 5.56.0 (29 May 2026) allowed declarations in the template. 5.57.0 (28 August 2026) exported RenderOutput, SyncRenderOutput, Csp and Sha256Source types from svelte/server, added a has function to createContext, defaultValue on <select> and getOrInsert/getOrInsertComputed on SvelteMap. The 5.57.1 and 5.57.2 patches (18 September and 6 October 2026) are mostly hydration, async and parser performance fixes, and 5.57.3 (26 October 2026) fixed a11y role checks, redundant attribute writes during hydration and state tracking in unowned deriveds. The Svelte 4 line last published 4.2.20 on 20 May 2025.

Project activity

Checked 17 November 2026: latest release 5.57.3 (published to npm on 26 October 2026, matching packages/svelte/package.json on main), MIT licence, about 89,300 stars (89,284) on the sveltejs/svelte repository, with 6,173 forks and a push on the day of checking. The repository is written in JavaScript, was created on 20 November 2016 and develops on main. The npm package is slightly older than that: the registry records its creation on 17 November 2016 and version 1.0.0 on 29 November 2016. Two small housekeeping details: the registry's next dist-tag still points at a 5.0.0 pre-release (5.0.0-next.272), and LICENSE.md carries a "2016-2025" copyright line. The changelog is in packages/svelte/CHANGELOG.md, documentation is published at svelte.dev from sources in the repository's documentation/docs folder, and the roadmap and Discord chat are linked from the README.

Enjoying this project?

Discover more amazing open-source projects on TechLogHub. We curate the best developer tools and projects.

Project
svelte
Created
November 17
Last Updated
November 17, 2026 at 01:41 PM

Maintain Svelte: Compiler-First UI Framework with Runes? Add the badge to your README

Show that the project is featured on TechLogHub and send readers to this write-up.

Featured on TechLogHub
[![Featured on TechLogHub](https://techloghub.com/badge-neutral.svg)](https://techloghub.com/open-source/svelte?utm_source=techloghub_badge&utm_medium=referral&utm_campaign=readme)

Find more projects like this

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.