Prerequisites
Before installing themes, ensure you have shadcn/ui set up in your Astro project with React integration. If you haven’t already:Installation
Install the theme system
Install the complete theme system with all 40+ themes:This installs:
lib/themes-config.ts- Theme configuration and metadatacomponents/theme-script.astro- Inline script for preventing FOUCcomponents/mode-toggle.tsx- React component for theme switchingstyles/themes/*.css- All 40+ theme CSS files
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
How it works
The Astro adapter uses an inline script for theme management to avoid hydration issues:Theme Script implementation
Theme Script implementation
Located at The
components/theme-script.astro:is:inline directive ensures the script runs before any other JavaScript, preventing FOUC.ModeToggle React component
ModeToggle React component
Located at
components/mode-toggle.tsx:Multi-tab synchronization
Multi-tab synchronization
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+:src/styles/themes/index.css
Customizing themes
All theme CSS files are insrc/styles/themes/. Each theme defines CSS variables:
src/styles/themes/supabase.css
TypeScript usage
You can programmatically change themes using the globalsetTheme function:
src/env.d.ts
Astro configuration
Ensure yourastro.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 freeclient: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