Skip to content

shadcn-svelte: shadcn/ui components for Svelte, and how to add them

Better Design

Direct answer

shadcn-svelte is an unofficial, community-led Svelte port of shadcn/ui: accessible components built with Bits UI and Tailwind CSS that a CLI copies into your project. This guide covers setup in SvelteKit and Vite, the CLI, theming, dark mode and the move to Svelte 5 and Tailwind v4, from the project's own docs.

A hand-drawn browser window with shadcn-svelte written in it and a short list of what it does.

shadcn-svelte gives you the component code, not a package

shadcn-svelte is an unofficial, community-led Svelte port of shadcn/ui. It is not affiliated with shadcn, but the team got his blessing before they made it. Its components are built with Bits UI and Tailwind CSS. It is open source under the MIT license, maintained by Huntabyte, CokaKoala and Aidan Bleser with many contributions from the community.

Most component libraries ship as an npm package that you import and then override. When a component does not fit your design system, you wrap it or write workarounds. shadcn-svelte copies each component's source into your project instead. To change a button, you edit the button file. Its docs put it this way: this is not a component library, it is how you build your component library.

Five principles shape every component

  • Open Code: the top layer of each component is open for you to change.
  • Composition: every component uses a common, composable interface, so each new one works the same way.
  • Distribution: a flat-file schema and a command-line tool share components across projects.
  • Beautiful Defaults: the default styles look good alone and fit together as one consistent system.
  • AI-Ready: the open code lets language models read, understand and improve your components.

Bits UI handles accessibility, and you handle the styles

shadcn-svelte follows a headless architecture. Bits UI, a headless component library for Svelte, supplies the behavior. Its docs list WAI-ARIA compliance, keyboard navigation by default, focus management and built-in screen reader support. Most Bits UI components ship unstyled, so the Tailwind classes in your copied files set the look.

Other headless libraries power some components: Formsnap for forms, Paneforge for resizable panels and Vaul Svelte for the drawer. This split answers the usual question about updates. You get fixes to the core by updating dependencies such as bits-ui or paneforge. The styled layer stays yours.

The components cover forms, overlays, data and AI chat

The component list runs from Accordion, Alert Dialog and Button to Calendar, Chart, Combobox, Data Table, Dialog, Drawer, Input OTP, Sidebar, Skeleton, Sonner, Table and Tooltip. A separate set, AI Elements, covers chat interfaces with parts such as Chat, Prompt Input, Message, Reasoning, Sources and Tool.

The Skeleton shows a placeholder while content loads. Add it with npx shadcn-svelte@latest add skeleton, then set its size with Tailwind classes:

Svelte
<script lang="ts">
  import { Skeleton } from "$lib/components/ui/skeleton/index.js";
</script>

<Skeleton class="h-[20px] w-[100px] rounded-full" />

How to install shadcn-svelte in SvelteKit

Install guides cover SvelteKit, Vite, Astro and a manual setup. For SvelteKit, create the project with Tailwind CSS using npx sv create my-app --add tailwindcss. If you do not use the default $lib alias, add your aliases to svelte.config.js.

Then run npx shadcn-svelte@latest init. It installs dependencies, adds the cn util and creates CSS variables. It asks a few questions to write components.json:

init prompts
Which base color would you like to use? › Slate
Where is your global CSS file? (this file will be overwritten) › src/routes/layout.css
Configure the import alias for lib: › $lib
Configure the import alias for components: › $lib/components
Configure the import alias for utils: › $lib/utils
Configure the import alias for hooks: › $lib/hooks
Configure the import alias for ui: › $lib/components/ui

Add your first component

Run npx shadcn-svelte@latest add button. The Button lands in your ui folder, and you import it like any of your own files:

Svelte
<script lang="ts">
  import { Button } from "$lib/components/ui/button/index.js";
</script>

<Button>Click me</Button>

shadcn-svelte in four steps

The four steps, in the order you take them.

A hand-drawn four-step path for shadcn-svelte: Create the project, Run init, Add components, Customize them.
  1. Step 1: Create the project
  2. Step 2: Run init
  3. Step 3: Add components
  4. Step 4: Customize them

In a plain Vite project, set up the $lib alias first

Add Tailwind with npx sv add tailwindcss. Add baseUrl and paths for $lib to compilerOptions in tsconfig.json and tsconfig.app.json. Then let Vite resolve the alias, and run init as above:

vite.config.ts
import path from "path";

export default defineConfig({
  // ... other options
  resolve: {
    alias: {
      $lib: path.resolve("./src/lib"),
    },
  },
});

Each component gets its own folder

In React's shadcn/ui, a whole component can live in one file. Svelte cannot define several components in one file, so shadcn-svelte splits them. The CLI creates a folder for each component, with an index.ts that exports its parts. The Accordion, for example, has four .svelte files. Rollup tree-shakes the parts you do not use.

TypeScript
import {
  Accordion,
  AccordionContent,
  AccordionItem,
  AccordionTrigger
} from "$lib/components/ui/accordion"

shadcn-svelte CLI commands

init
What it does

Installs dependencies, adds the cn util and creates CSS variables

Example

npx shadcn-svelte@latest init

add
What it does

Adds a component and its dependencies; --all adds every one, --overwrite replaces files

Example

npx shadcn-svelte@latest add button

apply
What it does

Applies a preset; --only theme or --only font applies just that part

Example

npx shadcn-svelte@latest apply <preset> --only theme

registry build
What it does

Generates registry JSON files for your own components

Example

npx shadcn-svelte@latest registry build

Theming works through CSS variables

shadcn-svelte styles components with CSS variables, so you change colors without editing class names. It uses a background and foreground convention. --primary sets a component's background and --primary-foreground sets its text, and the class bg-primary text-primary-foreground uses both. Values are OKLCH colors under :root, with overrides under .dark.

init offers these base colors: neutral, stone, zinc, mauve, olive, mist and taupe. To add your own color, define it for both modes and map it in @theme inline:

src/routes/layout.css
:root {
  --warning: oklch(0.84 0.16 84);
  --warning-foreground: oklch(0.28 0.07 46);
}

.dark {
  --warning: oklch(0.41 0.11 46);
  --warning-foreground: oklch(0.99 0.02 95);
}

@theme inline {
  --color-warning: var(--warning);
  --color-warning-foreground: var(--warning-foreground);
}

Add dark mode with mode-watcher

For a Svelte app, install mode-watcher and put its ModeWatcher component in your root layout. Then add a light switch or a dropdown menu to toggle the mode. Astro has its own dark mode guide.

src/routes/+layout.svelte
<script lang="ts">
  import "./layout.css";
  import { ModeWatcher } from "mode-watcher";
  let { children } = $props();
</script>

<ModeWatcher />
{@render children?.()}

The current docs target Svelte 5 and Tailwind v4

The @latest CLI sets up new projects with Svelte 5 and Tailwind v4. Tailwind v4 support landed in May 2025. The change is non-breaking: Tailwind v3 apps keep working, and new components keep your configured style until you upgrade. Tailwind v4 uses new browser features and is designed for modern browsers, so read its compatibility docs first.

The Tailwind v4 release brought these changes:

  • Support for the @theme directive and the @theme inline option.
  • A data-slot attribute on every primitive that renders an element, for styling.
  • HSL colors converted to OKLCH.
  • The default style deprecated; new projects use new-york.
  • Buttons now use the default cursor.

Upgrade an older project in two steps

Move from Svelte 4 to Svelte 5 first, while you stay on Tailwind 3. Commit your changes, note which components you customized, and use sv-migrate to help. Then follow the Tailwind v4 guide, which uses the @tailwindcss/upgrade codemod and replaces PostCSS with @tailwindcss/vite. Legacy docs stay online for Svelte 5 with Tailwind v3, and for Svelte 4 with Tailwind v3.

Things to know before you use shadcn-svelte

  • init overwrites your global CSS file, so commit it first.
  • The project is not affiliated with shadcn, so features can lag the React version.
  • Components span several files, so use the CLI rather than copying single files by hand.
  • add --overwrite replaces existing files, including your edits.
  • The Svelte 5 migration guide covers only the shadcn-svelte parts. Bits UI has its own migration guide.

Steal this workflow

Run this guide in your own assistant. The prompt carries the guide link and the workflow summary, so the assistant can adapt it to your project.

Read the guide "shadcn-svelte: shadcn/ui components for Svelte, and how to add them" at https://better-design.com/blog/shadcn-svelte and help me apply it to my project.

shadcn-svelte is an unofficial, community-led Svelte port of shadcn/ui: accessible components built with Bits UI and Tailwind CSS that a CLI copies into your project. This guide covers setup in SvelteKit and Vite, the CLI, theming, dark mode and the move to Svelte 5 and Tailwind v4, from the project's own docs.

Start by asking what I am building and which tools I use. Then walk me through the workflow step by step, adapted to my answers.

Claude and ChatGPT open with the prompt filled in. Gemini copies the prompt to your clipboard first, so paste it when the app opens.

Questions

Is shadcn-svelte official?

No. It is a community-led port, made with shadcn's blessing but not affiliated with him.

What is shadcn-svelte built on?

Bits UI for the component behavior and Tailwind CSS for the styles. Formsnap, Paneforge and Vaul Svelte power some components.

How do I add a component to shadcn-svelte?

Run npx shadcn-svelte@latest add followed by the component name, such as button. Use --all to add every component.

Does shadcn-svelte support Svelte 5 and Tailwind v4?

Yes. The @latest CLI sets up new projects with Svelte 5 and Tailwind v4, and migration guides cover older projects.

Are shadcn-svelte components accessible?

They are built on Bits UI, whose docs list WAI-ARIA compliance, keyboard navigation, focus management and screen reader support.

Where these shadcn-svelte facts come from

Each fact comes from the pages listed here, read on November 15, 2026. Products change, so check those pages for the current version.

Build the interface in your own code instead

A coding agent such as Claude Code, Cursor or Codex can build your interface in your own code. Better Design gives that agent a design system, interface principles and review rules, so the result looks designed.