Svelte Tutorial
Learn Svelte step by step: 35 lessons in 10 chapters with examples, quizzes, diagrams and projects.
Start learning →
of lessons completed
Getting Started
- What Is Svelte? Learn what Svelte is, how a compiler-first framework differs from a runtime library, and what you can build with Svelte 5 and its runes.
- Setting Up a Svelte Project Create a Svelte 5 project with the sv CLI or Vite, understand the folder layout, run the dev server, and mount your first component.
- Anatomy of a Svelte Component Understand the three parts of a Svelte 5 component: script, markup and scoped style, plus module scripts, imports and how components nest.
- The Svelte Compiler and Your Bundle See what the Svelte compiler produces, how it tracks dependencies, what warnings it gives, and why Svelte bundles are small.
Reactivity with Runes
- Reactive State with $state Learn the $state rune in Svelte 5: declaring reactive variables, updating them, objects and arrays, class fields, and common mistakes.
- Derived Values with $derived Compute values from state with the $derived rune in Svelte 5, use $derived.by for longer logic, and avoid the effect-for-everything trap.
- Side Effects with $effect Use the $effect rune in Svelte 5 for side effects like logging, timers and DOM work, with cleanup functions, $effect.pre and when not to use effects.
- Deep Reactivity and Snapshots How Svelte 5 proxies make objects and arrays deeply reactive, when to use $state.raw, $state.snapshot, SvelteMap and SvelteSet, and what breaks proxies.
Templates and Markup
- Text, Expressions and Attributes Put JavaScript into Svelte markup: text expressions, dynamic attributes, shorthand, spread, class and style directives, and {@html} safety.
- Conditional Rendering with {#if} Show and hide markup in Svelte 5 with {#if}, {:else if} and {:else}, plus {#key}, {#await} for promises and patterns for loading and empty states.
- Lists with {#each} Render lists in Svelte 5 with {#each}: index, keys for stable updates, destructuring, empty states and iterating over objects, Maps and ranges.
- Events and Bindings Handle DOM events with onclick-style attributes in Svelte 5 and bind form values with bind:value, bind:checked, bind:group and bind:this.
Components
- Component Props Pass data into Svelte 5 components with the $props rune: defaults, renaming, rest props, spreading, TypeScript types and why props are reactive.
- Snippets and Children Pass markup into components with Svelte 5 snippets: the children prop, named snippets with parameters, {@render}, and why they replace slots.
- Callback Props and $bindable Send events from child to parent in Svelte 5 with callback props, expose two-way props with $bindable, and learn when each pattern fits.
State Beyond One Component
- Shared State in Modules Share state between Svelte 5 components using .svelte.js modules: exported objects, classes and getter functions, plus the rules that keep it reactive.
- The Context API Share data with a component subtree using setContext and getContext in Svelte 5, combine it with reactive state, and avoid global state issues.
- Svelte Stores Learn svelte/store in Svelte 5: writable, readable and derived stores, the $store auto-subscription syntax, custom stores, and when runes are enough.
Motion and Polish
- Transitions and In/Out Animations Learn Svelte transitions: transition:fade, in: and out:, built-in fly, slide and scale effects, easing, local vs global, events and writing your own.
- Animating Lists with animate:flip and crossfade Animate reordered lists with animate:flip, move items between lists with crossfade, learn the FLIP technique, keyed each requirements and custom animate functions.
- Tween and Spring for Smooth Values Animate numeric state in Svelte 5 with the Tween and Spring classes from svelte/motion - duration, easing, stiffness, damping, reduced motion and when to use each.
SvelteKit
- SvelteKit Routing and Layouts Learn SvelteKit file-based routing - +page.svelte, +layout.svelte, dynamic [param] routes, optional and rest params, route groups, error pages and navigation.
- SvelteKit Load Functions and Data Flow Fetch data in SvelteKit with load functions - universal vs server load, params, fetch, parent data, streaming promises, invalidation, errors and redirects.
- Form Actions and Progressive Enhancement Handle forms in SvelteKit with actions - default and named actions, FormData, validation with fail(), redirect after success, use:enhance and the form prop.
- Hooks and Server Endpoints in SvelteKit Use SvelteKit hooks (handle, handleError, handleFetch) for auth and logging, chain them with sequence, and build JSON API routes with +server.js and RequestHandlers.
- Rendering Modes and Deploying SvelteKit Choose between SSR, prerendering, static sites and SPA mode in SvelteKit, set ssr, csr and prerender page options, handle env vars and pick the right adapter.
Quality
- Testing Svelte Components and Logic Test Svelte 5 apps with Vitest, @testing-library/svelte and Playwright - unit tests for logic, component tests, testing runes in .svelte.js files and end-to-end tests.
- Accessibility in Svelte and the a11y Warnings Build accessible Svelte apps - the compiler's a11y warnings explained, semantic HTML, labels, keyboard support, focus management, ARIA live regions and svelte-ignore.
- Debugging and Performance in Svelte Debug Svelte 5 with $inspect, $inspect.trace, {@debug} and devtools, then speed up apps with keyed each blocks, $derived, $state.raw, lazy loading and bundle checks.
- TypeScript in Svelte Use TypeScript in Svelte 5 - lang="ts", typed $props, $state generics, Snippet and event types, generic components, .svelte.ts modules and svelte-check.
Projects
- Project: A Todo App with Runes Build a complete todo app in Svelte 5 with $state, $derived, a shared class store, components, filters and localStorage persistence, plus a runnable plain-JS demo.
- Project: Live Search with Debounce and Loading States Build a live search box in Svelte 5 - debounced input, cancelling stale requests with AbortController, loading, empty and error states, highlighting and keyboard navigation.
- Project: A Markdown Blog with SvelteKit Build a fast, SEO-friendly blog in SvelteKit - Markdown posts with front matter, import.meta.glob, dynamic routes, entries(), prerendering, an RSS feed and a 404 page.
Practice and Review
- Svelte Practice Exercises with Solutions Twelve Svelte 5 practice exercises on runes, bindings, each blocks, props, snippets, stores and SvelteKit, with hints and worked solutions you can check in your browser.
- Svelte and SvelteKit Interview Questions Prepare for Svelte interviews with clear answers on runes, reactivity, compilation, components, snippets, SvelteKit data loading, SSR, performance and common pitfalls.