Svelte is a revolutionary compiler-based UI framework for building web applications, currently at version 5.55.4. Unlike traditional frameworks that operate at runtime, Svelte shifts the work to compile time, converting declarative components into highly efficient JavaScript that surgically updates the DOM. This approach results in smaller bundle sizes, faster initial load times, and improved runtime performance, as it eliminates the need for a virtual DOM or a large runtime library. Svelte 5, with its new 'runes' API, introduces a universal, fine-grained reactivity system that makes state management more explicit and consistent across components and standalone JavaScript/TypeScript files. It maintains a rapid release cadence, frequently pushing patch updates and incorporating minor features, while major versions like Svelte 5 introduce significant, yet often incrementally adoptable, paradigm shifts. Key differentiators include its compile-time approach, the absence of a virtual DOM, and the new runes-based reactivity that aims for a more intuitive and performant developer experience.
npm install svelteVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a SvelteKit project with Svelte 5, showcasing the new `$state`, `$derived`, and `$effect` runes for reactive state management within a component. It includes a simple counter and multiplier that update the UI reactively.
Migrate `let` declarations to `$state(initialValue)`. Replace `$: variable = expression` for computed values with `const variable = $derived(expression)`. Replace `$: { sideEffect() }` with `$effect(() => { sideEffect() })`. A migration script is available to assist with some of these changes.Transition from `<slot>` to `{@render ...}` with snippets for passing content to components. Review Svelte 5 documentation for detailed snippet usage.Update event listeners from `on:eventName` to `onEventName`. Replace usage of `createEventDispatcher` with direct prop-based callback functions for child-to-parent communication.
Avoid direct `bind:` to exported properties of components in runes mode. Use `bind:this={componentInstance}` and access properties on `componentInstance` instead.Prioritize `$state`, `$derived`, and `$effect` for reactive state and effects within components and `.svelte.js` files. Reserve traditional `writable` and `readable` stores for genuinely global, shared, or complex asynchronous data streams.
Ensure `$state`, `$derived`, and `$effect` declarations are within a `<script>` tag of a `.svelte` component or a `.svelte.js`/`.svelte.ts` file, and that they are initialized correctly before usage.
If using Svelte 4 stores, ensure `storeName` is an actual store imported from `svelte/store`. If in Svelte 5, use the explicit `$state(value)`, `$derived(expression)`, or `$effect(() => { ... })` runes, imported from 'svelte'. The `$` prefix for stores is still supported for compatibility but runes are preferred.`$derived` values are read-only and automatically update when their dependencies change. To change the value, modify the underlying `$state` variable(s) it depends on, rather than the `$derived` variable itself.
No dependency data recorded yet.