Astro
Complete guide to installing tweakcn/theme-picker themes in your Astro project with React islands. Uses inline scripts for instant theme application.
Prerequisites
Keep :root and .dark as fallbacks
tweakcn/theme-picker themes use data-theme attributes. Keep your :root and .dark variable blocks as fallbacks to prevent flash of unstyled content before the theme loads.
Installation
Install the theme system
Run this single command to install the complete theme system for Astro. This includes all 42+ themes, the theme scripts, and all theme CSS.
$ pnpm dlx shadcn@latest add https://tweakcn-picker.vercel.app/r/astro/theme-system.jsonCreate an inline theme script
Add this inline script to your layout to apply the theme before the page renders:
1---2import '../styles/globals.css'3---45<html lang="en">6 <head>7 <meta charset="UTF-8" />8 <meta name="viewport" content="width=device-width" />9 <link rel="icon" type="image/svg+xml" href="/favicon.svg" />10 <title>My Astro Site</title>11 <!-- Flash Prevention: Apply theme before render -->12 <script is:inline>13 (function() {14 var stored = localStorage.getItem("tweakcn-theme");15 if (stored) {16 document.documentElement.setAttribute("data-theme", stored);17 } else {18 // Respect system preference for first-time visitors19 var isDark = window.matchMedia("(prefers-color-scheme: dark)").matches;20 document.documentElement.setAttribute("data-theme", isDark ? "default-dark" : "default-light");21 }22 })();23 </script>24 </head>25 <body>26 <slot />27 </body>28</html>Use the included ThemeSwitcher
The CLI installs a complete ThemeSwitcher component. Use it with the client:load directive:
1---2import Layout from '../layouts/Layout.astro';3import { ThemeSwitcher } from '@/components/theme-switcher';4---56<Layout>7 <main>8 <h1>Welcome to Astro</h1>9 <ThemeSwitcher client:load />10 </main>11</Layout>The ThemeSwitcher includes a dropdown menu with all available themes, light/dark mode toggle, and displays the current theme with a color indicator.
Install Individual Themes
$ pnpm dlx shadcn@latest add https://tweakcn-picker.vercel.app/r/theme-catppuccin.jsonReplace theme-catppuccin with any theme: theme-claude, theme-vercel, etc.
inline scripts as shown above.