Skip to main content
SvelteKit with DaisyUI provides a compiler-based framework for building blazing-fast web applications with minimal bundle sizes.

Overview

SvelteKit compiles your code to highly optimized vanilla JavaScript, resulting in smaller bundles and better runtime performance.

Pre-installed Packages

  • SvelteKit: Full-stack framework with file-based routing
  • Svelte: Compiler-based UI framework
  • DaisyUI: Tailwind CSS component library
  • Tailwind CSS: Utility-first CSS framework
  • TypeScript: Full type safety
  • Vite: Fast development server and build tool

Key Features

  • Compile-time framework (no virtual DOM)
  • Reactive declarations with $:
  • Built-in state management
  • File-based routing
  • Server-side rendering
  • Zero-config setup
  • Smallest bundle sizes

Use Cases

SvelteKit is best suited for:

Performance-Critical Apps

Applications requiring minimal bundle size and maximum performance

Fast Websites

Sites that prioritize loading speed and runtime performance

Simple Syntax Projects

Projects that benefit from Svelte’s straightforward syntax

Full-Stack Apps

Applications using SvelteKit’s server-side capabilities

DaisyUI Components

DaisyUI is a plugin for Tailwind CSS that provides semantic component classes without JavaScript dependencies.

Available Components

  • Actions: Button, Dropdown, Modal, Swap
  • Data Display: Accordion, Avatar, Badge, Card, Carousel, Chat Bubble, Collapse, Countdown, Kbd, Stat, Table, Timeline
  • Navigation: Breadcrumbs, Bottom Navigation, Link, Menu, Navbar, Pagination, Steps, Tabs
  • Feedback: Alert, Loading, Progress, Radial Progress, Skeleton, Toast, Tooltip
  • Data Input: Checkbox, File Input, Radio, Range, Rating, Select, Text Input, Textarea, Toggle
  • Layout: Artboard, Divider, Drawer, Footer, Hero, Indicator, Join, Mask, Stack
  • Mockup: Browser, Code, Phone, Window

Component Usage

<script lang="ts">
  function handleClick() {
    console.log('Button clicked');
  }
</script>

<div class="flex gap-2">
  <button class="btn">Default</button>
  <button class="btn btn-primary">Primary</button>
  <button class="btn btn-secondary">Secondary</button>
  <button class="btn btn-accent">Accent</button>
  <button class="btn btn-ghost">Ghost</button>
  <button class="btn btn-link">Link</button>
  <button class="btn" on:click={handleClick}>Click Me</button>
</div>

Critical Rules

Main File: The main page is src/routes/+page.svelte. Layout is in src/routes/+layout.svelte.
Pre-installed: DaisyUI and Tailwind CSS are already installed. Do not run installation commands for these packages.

File Conventions

  • Page files: +page.svelte (in routes/)
  • Layout files: +layout.svelte (in routes/)
  • Component files: ComponentName.svelte (PascalCase)
  • Components directory: src/lib/components/
  • Utilities directory: src/lib/utils/
  • Types directory: src/lib/types/
  • Stores directory: src/lib/stores/

Component Structure

<script lang="ts">
  import { onMount } from 'svelte';
  
  // Props
  export let title: string;
  export let count = 0;
  
  // Reactive declarations
  $: doubled = count * 2;
  $: isEven = count % 2 === 0;
  
  // Functions
  function increment() {
    count++;
  }
  
  // Lifecycle
  onMount(() => {
    console.log('Component mounted');
  });
</script>

<div>
  <h1>{title}</h1>
  <p>Count: {count}</p>
  <p>Doubled: {doubled}</p>
  <p>Is even: {isEven}</p>
  <button class="btn" on:click={increment}>Increment</button>
</div>

<style>
  /* Component-scoped styles or use Tailwind classes */
</style>

Project Structure

src/
├── routes/
│   ├── +page.svelte      # Main page
│   └── +layout.svelte    # Root layout
├── lib/
│   ├── components/       # Reusable components
│   ├── stores/           # Svelte stores
│   ├── utils/            # Utility functions
│   └── types/            # TypeScript types
└── app.html              # HTML template

Reactive Declarations

Svelte’s reactive declarations automatically update when dependencies change:
<script lang="ts">
  let count = 0;
  
  // Automatically recalculates when count changes
  $: doubled = count * 2;
  $: tripled = count * 3;
  $: message = count > 10 ? 'High' : 'Low';
</script>

<div>
  <p>Count: {count}</p>
  <p>Doubled: {doubled}</p>
  <p>Tripled: {tripled}</p>
  <p>Status: {message}</p>
  <button class="btn" on:click={() => count++}>Increment</button>
</div>

Svelte Stores

For global state management:
// src/lib/stores/counter.ts
import { writable, derived, readable } from 'svelte/store';

// Writable store
export const count = writable(0);

export function increment() {
  count.update(n => n + 1);
}

export function decrement() {
  count.update(n => n - 1);
}

export function reset() {
  count.set(0);
}

// Derived store
export const doubled = derived(count, $count => $count * 2);

// Readable store
export const time = readable(new Date(), function start(set) {
  const interval = setInterval(() => {
    set(new Date());
  }, 1000);

  return function stop() {
    clearInterval(interval);
  };
});
<!-- Usage in component -->
<script lang="ts">
  import { count, doubled, increment, decrement, reset } from '$lib/stores/counter';
</script>

<div>
  <p>Count: {$count}</p>
  <p>Doubled: {$doubled}</p>
  <button class="btn" on:click={increment}>+</button>
  <button class="btn" on:click={decrement}>-</button>
  <button class="btn" on:click={reset}>Reset</button>
</div>

DaisyUI Theming

DaisyUI includes multiple built-in themes:
<!-- src/app.html -->
<html data-theme="light">
  <!-- Available themes:
    light, dark, cupcake, bumblebee, emerald, corporate, synthwave,
    retro, cyberpunk, valentine, halloween, garden, forest, aqua,
    lofi, pastel, fantasy, wireframe, black, luxury, dracula
  -->
</html>

Conditional Rendering & Loops

<script lang="ts">
  let loggedIn = false;
</script>

{#if loggedIn}
  <p>Welcome back!</p>
{:else}
  <button class="btn">Login</button>
{/if}

Best Practices

<script>
  let firstName = 'John';
  let lastName = 'Doe';
  
  // Automatically updates when firstName or lastName change
  $: fullName = `${firstName} ${lastName}`;
</script>
// lib/stores/user.ts
import { writable } from 'svelte/store';
export const user = writable(null);
<input class="input" bind:value={name} />
<!-- Instead of value={name} on:input={...} -->
<script>
  import { fade, slide } from 'svelte/transition';
</script>

{#if visible}
  <div transition:fade>Fades in and out</div>
  <div transition:slide>Slides in and out</div>
{/if}
<!-- Card.svelte -->
<div class="card">
  <slot name="header" />
  <slot />
  <slot name="footer" />
</div>

<!-- Usage -->
<Card>
  <h2 slot="header">Title</h2>
  <p>Content</p>
  <button slot="footer" class="btn">Action</button>
</Card>

Getting Started

Framework Overview

Examples

API Reference

Build docs developers (and LLMs) love