Skip to main content
1

Create project

Start by creating a new Astro project:
npm create astro@latest
2

Configure your Astro project

You will be asked a few questions to configure your project:
- Where should we create your new project?
./your-app-name
- How would you like to start your new project?
Choose a starter template (or Empty)
- Install dependencies?
Yes
- Initialize a new git repository? (optional)
Yes/No
3

Add Svelte to your project

Install Svelte using the Astro CLI:
npx astro add svelte
Answer Yes to all the question prompted by the CLI when installing Svelte.
4

Add TailwindCSS to your project

Add Tailwind CSS using the Astro CLI:
npx astro add tailwind
Answer Yes to all the question prompted by the CLI when installing TailwindCSS.
5

Import the global CSS file

Import the global.css file in the src/pages/index.astro file:
src/pages/index.astro
---
import "../styles/global.css";
---
6

Setup path aliases

Add the following code to the tsconfig.json file to resolve paths:
tsconfig.json
{
  "compilerOptions": {
    // ...
    "baseUrl": ".",
    "paths": {
      "$lib": ["./src/lib"],
      "$lib/*": ["./src/lib/*"]
    }
    // ...
  }
}
If needed, adapt the path aliases to your specific needs (learn more about it).
7

Run the CLI

Run the shadcn-svelte init command to setup your project:
npx shadcn-svelte@latest init
8

Configure components.json

You will be asked a few questions to configure components.json:
Which base color would you like to use? › Slate
Where is your global CSS file? (this file will be overwritten) › src/styles/global.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
9

That's it

You can now start adding components to your project.
npx shadcn-svelte@latest add button
The command above will add the Button component to your project. You can then import it like this:
index.astro
---
import { Button } from "$lib/components/ui/button/index.js";
---

<html lang="en">
  <head>
    <title>Astro</title>
  </head>
  <body>
    <Button>Hello World</Button>
  </body>
</html>
Remember to use the client directives inside .astro files when dealing with interactive components (learn more about it).

Build docs developers (and LLMs) love