A hands-on practice repository for learning Svelte 5 and SvelteKit fundamentals, featuring modern Svelte Runes and reactive state management.
$state - Local reactive state management$derived - Computed/derived state from other reactive values$effect - Side effects and lifecycle management with cleanup$props - Component props with TypeScript types$inspect - Debugging reactive state changes$state.snapshot - Capturing state snapshots for logging{...props}){#if}, {:else if}, {:else}{#each} blocks and keyed iterations{#await} blocks (:then, :catch)+server.ts files (SvelteKit)$state rune$derived+page.svelte files+layout.svelte (root and nested layouts)[slug] syntax+page.server.ts and +layout.server.tssrc/
├── routes/
│ ├── +page.svelte # Homepage with component examples
│ ├── +layout.svelte # Root layout component
│ ├── logic/
│ │ └── +page.svelte # Logic/conditionals demo page
│ ├── events/
│ │ └── +page.svelte # Event handling demo page
│ ├── bindings/
│ │ └── +page.svelte # Form bindings demo page
│ ├── classes-styles/
│ │ └── +page.svelte # Classes and styles demo page
│ ├── actions/
│ │ └── +page.svelte # Actions demo page
│ ├── transitions/
│ │ └── +page.svelte # Transitions demo page
│ ├── stores/
│ │ ├── +page.svelte # Stores demo page
│ │ └── components/
│ │ └── ResetCount.svelte # Store consumer component
│ ├── snippets/
│ │ └── +page.svelte # Snippets demo page
│ ├── context/
│ │ ├── +page.svelte # Context API demo page
│ │ └── components/
│ │ ├── UserAvatar.svelte # Context consumer
│ │ └── UserProfileUpdate.svelte # Context updater
│ ├── blog/
│ │ ├── +layout.svelte # Blog root layout with navigation
│ │ ├── +page.svelte # Blog listing page
│ │ ├── +page.server.ts # Load blog post summaries
│ │ └── [slug]/ # Dynamic route for individual posts
│ │ ├── +layout.svelte # Nested layout with sidebar
│ │ ├── +layout.server.ts # Load related posts
│ │ ├── +page.svelte # Individual blog post page
│ │ └── +page.server.ts # Load specific post data
│ ├── form-actions/
│ │ ├── +page.svelte # Form actions demo (todo app)
│ │ └── +page.server.ts # Server-side form actions & data loading
│ └── api-routes/
│ └── +page.svelte # API routes documentation page
├── actions/
│ └── trapFocus.svelte.ts # Focus trap action
├── lib/
│ └── server/
│ └── db.ts # Mock database for form actions demo
├── store/
│ └── store.ts # Global stores (writable, readable, derived)
├── componets/ # Component library
│ ├── BasicCounter.svelte # Local state example
│ ├── Counter.svelte # Global state example
│ ├── ArrayState.svelte # Array state & $derived
│ ├── TimerEffect.svelte # $effect rune with cleanup
│ ├── User.svelte # Props & TypeScript
│ ├── Nested.svelte # Component composition
│ ├── Stepper.svelte # Component events (callback props)
│ ├── TextBinding.svelte # Text input binding
│ ├── NumericBinding.svelte # Numeric input binding
│ ├── TextareaBinding.svelte # Textarea binding
│ ├── CheckboxBinding.svelte # Checkbox binding
│ ├── SelectElement.svelte # Select element binding
│ ├── GroupInputs.svelte # Radio & checkbox groups
│ ├── Box.svelte # Component with CSS custom properties
│ ├── Canvas.svelte # Drawing canvas component
│ └── Snippets.svelte # Component demonstrating snippets
└── shared/
├── shared.svelte.ts # Global state store
└── data.ts # Mock blog post data
If you're seeing this, you've probably already done this step. Congrats!
# create a new project in the current directory
npx sv create
# create a new project in my-app
npx sv create my-app
npm install
# or
pnpm install
# or
yarn
Start a development server:
npm run dev
# or start the server and open the app in a new browser tab
npm run dev -- --open
To create a production version of your app:
npm run build
You can preview the production build with npm run preview.
To deploy your app, you may need to install an adapter for your target environment.
See BasicCounter.svelte for a simple counter using $state rune.
See Counter.svelte and shared.svelte.ts for shared state across multiple components.
See ArrayState.svelte for $derived and array state management.
See TimerEffect.svelte for $effect with interval cleanup.
See User.svelte for typed component props using $props rune.
See logic/+page.svelte for comprehensive examples:
{#if}, {:else if}, {:else} blocks{#each} blocks{#await} blocks (promise handling, API calls)See events/+page.svelte for event handling patterns:
on:eventname (e.g., onpointermove, onclick)oneventnamecapturepreventDefault, stopPropagation, once, etc.See bindings/+page.svelte for comprehensive binding examples:
bind:value for two-way data binding with text inputsbind:checked for boolean checkbox statebind:group for radio button groups and checkbox groupsSee classes-styles/+page.svelte for styling patterns:
class={condition ? 'active' : ''}style:property={value}--variable props:global() to target elements inside other componentsstyle:color when variable name matches CSS propertySee actions/+page.svelte for actions patterns:
use:actionName on any elementtrapFocus actionSee transitions/+page.svelte for transition patterns:
fade, fly, slide, scale, blur, and draw transitionsin: and out: directives for different enter/exit animationstick functiononintrostart, onintroend, onoutrostart, onoutroend{#key} blockstransition:name|global to play transitions on parent block changesSee stores/+page.svelte and store/store.ts for store patterns:
writable() for shared statereadable() for streaming data (e.g., time updates)derived()$store syntax in components to automatically subscribe/unsubscribestore.subscribe() outside components (remember to unsubscribe)set() to replace values or update() to transform valuesSee snippets/+page.svelte for snippet patterns:
{#snippet name(params)}...{/snippet} to create reusable template chunks{@render name(args)} to render snippetsSee context/+page.svelte for context patterns:
SvelteMap or other reactive data structures for automatic updatesSee blog/ for comprehensive routing and layout patterns:
+page.svelte files in the routes directory+layout.svelte to wrap all pages with shared UI (navigation, footer)[param] syntax to create parameter-based routes (e.g., /blog/[slug])+page.server.ts and +layout.server.ts to fetch data before renderingload() functions to make it available to pages via $props()error() function to throw 404 or other HTTP errorsSee form-actions/+page.svelte and form-actions/+page.server.ts for form action patterns:
+page.server.ts to handle POST requests (create, delete, update)form prop?/actionName syntaxfail() and display them to usersActions and PageServerLoad typesSee api-routes/+page.svelte for API routes documentation:
+server.ts filesjson() helper[param] syntax