Next.js
Complete guide to installing tweakcn/theme-picker themes in your Next.js application. Works with both App Router and Pages Router.
Prerequisites
Flash Prevention Setup
tweakcn/theme-picker uses data-theme attributes. To prevent flash on load, you need:
- :root fallback in CSS with your default theme colors
- Inline script in <head> to set data-theme before render
- Optional:
@media (prefers-color-scheme)for system preference support
Installation
Install the theme system
Run this single command to install the complete theme system. This includes all 42+ themes, the ThemeProvider component, theme CSS, and configures next-themes automatically.
$ pnpm dlx shadcn@latest add https://tweakcn-picker.vercel.app/r/nextjs/theme-system.jsonSet up your root layout
Add the ThemeProvider and flash prevention script to your root layout. The inline script in <head> runs before React hydrates, preventing any flash of unstyled content.
1import { ThemeProvider } from "@/components/providers/theme-provider"23export default function RootLayout({4 children,5}: {6 children: React.ReactNode7}) {8 return (9 <html lang="en" suppressHydrationWarning>10 <head>11 {/* Flash Prevention: Apply theme before render */}12 <script13 dangerouslySetInnerHTML={{14 __html: `15 (function() {16 const stored = localStorage.getItem('theme');17 if (stored) {18 document.documentElement.setAttribute('data-theme', stored);19 } else {20 const isDark = window.matchMedia('(prefers-color-scheme: dark)').matches;21 document.documentElement.setAttribute('data-theme', isDark ? 'default-dark' : 'default-light');22 }23 })();24 `,25 }}26 />27 </head>28 <body>29 <ThemeProvider30 attribute="data-theme"31 defaultTheme="default-dark"32 enableSystem={false}33 disableTransitionOnChange34 >35 {children}36 </ThemeProvider>37 </body>38 </html>39 )40}data-theme immediately. This prevents flash because CSS variables are applied before the first paint. Add suppressHydrationWarning to prevent hydration warnings.Import theme styles
The CLI adds the theme imports to your globals.css automatically. Verify it looks like this:
1@import "tailwindcss";23/* tweakcn/theme-picker theme imports */4@import "../styles/index.css";56@layer base {7 * {8 @apply border-border;9 }10 body {11 @apply bg-background text-foreground;12 }13}Use the included ThemeSwitcher
The CLI installs a complete ThemeSwitcher component that lets users switch between all 42+ themes and toggle light/dark modes. Import and use it anywhere in your app:
1import { ThemeSwitcher } from "@/components/theme-switcher"23export function Header() {4 return (5 <header>6 <nav>{/* ... */}</nav>7 <ThemeSwitcher />8 </header>9 )10}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, theme-cyberpunk, etc.
ThemeProvider and imports as shown above.ThemeProvider Configuration
The ThemeProvider accepts several props to customize behavior:
| Prop | Type | Description |
|---|---|---|
| attribute | string | HTML attribute to apply theme. Use "data-theme" for tweakcn/theme-picker. |
| defaultTheme | string | Default theme. Format: "theme-name-light" or "theme-name-dark" |
| themes | string[] | Array of available themes. Pre-configured with all tweakcn/theme-picker themes. |
| enableSystem | boolean | Whether to use system preference. Set to false for manual control. |
Available Theme Values
Each theme has both light and dark variants. Use these values with setTheme():
[theme-name]-light[theme-name]-darkExamples:- default-light / default-dark- catppuccin-light / catppuccin-dark- claude-light / claude-dark- vercel-light / vercel-dark- cyberpunk-light / cyberpunk-dark