Skip to main content

Prerequisites

Before installing themes, ensure you have shadcn/ui set up in your Astro project with React integration. If you haven’t already:
1

Add React to Astro

2

Initialize shadcn/ui

3

Install required components

The theme system requires these shadcn/ui components:

Installation

1

Install the theme system

Install the complete theme system with all 40+ themes:
This installs:
  • lib/themes-config.ts - Theme configuration and metadata
  • components/theme-script.astro - Inline script for preventing FOUC
  • components/mode-toggle.tsx - React component for theme switching
  • styles/themes/*.css - All 40+ theme CSS files
2

Add theme script to your layout

Add the theme script component in the <head> of your base layout to prevent flash of unstyled content (FOUC):
src/layouts/Layout.astro
The ThemeScript component must be placed in the <head> tag to work correctly and prevent FOUC.
3

Add the ModeToggle to your UI

Import and use the ModeToggle component in any .astro or .tsx file:
src/components/Header.astro
The client:load directive is required for React components to be interactive in Astro.

How it works

The Astro adapter uses an inline script for theme management to avoid hydration issues:
Located at components/theme-script.astro:
The is:inline directive ensures the script runs before any other JavaScript, preventing FOUC.
Located at components/mode-toggle.tsx:
The theme script includes multi-tab synchronization using the Storage API:
When you change the theme in one tab, all other tabs automatically update.

Adding individual themes

To install specific themes instead of all 40+:
Then import only the themes you need:
src/styles/themes/index.css

Customizing themes

All theme CSS files are in src/styles/themes/. Each theme defines CSS variables:
src/styles/themes/supabase.css
Edit these files to customize colors, borders, shadows, and more.

TypeScript usage

You can programmatically change themes using the global setTheme function:
Add TypeScript declarations for the global function:
src/env.d.ts

Astro configuration

Ensure your astro.config.mjs includes the React integration:
astro.config.mjs

Client directives

When using React components in Astro, choose the appropriate client directive:
  • client:load - Hydrates immediately on page load (recommended for theme toggle)
  • client:idle - Hydrates when the main thread is free
  • client:visible - Hydrates when the component enters the viewport

Next steps

Browse Themes

Explore all 40+ available themes

Theme Picker

Preview themes in real-time

Next.js Setup

Install themes in Next.js

Vite Setup

Install themes in Vite React