next-themes · shadcn/ui · Tailwind CSS v4

One component. 12 colors. Any hue. Zero flash.

Light and dark mode from next-themes, plus a color layer that lives in a singledata-themeattribute. Pick a color below, or dial in your own hue, and every button, chart and form updates instantly.

Now showing Default · Neutral zinc

See it in action

Every component below reads from the same CSS tokens. Change the theme and watch them follow.

Add it to your app

One command with the shadcn CLI, or copy the files by hand.

Install with the shadcn CLI

Installs the provider, hook, switcher, swatches and mode toggle, adds the theme CSS to your globals.css and pulls in next-themes and the button component. Works with any shadcn/ui style.

bash
npx shadcn@latest add https://next-themes-colors.vercel.app/r/theme-switcher.json

Or set it up by hand

  1. 1

    Add the theme tokens

    Paste the color theme block from globals.css. A theme is just a hue and a chroma; primary, ring, accent and the chart series are derived for light and dark mode.

    globals.css
    [data-theme="red"]  { --theme-hue: 25;  --theme-chroma: 0.215; }
    [data-theme="blue"] { --theme-hue: 262; --theme-chroma: 0.21; --theme-l: 0.56; }
    
    [data-theme]:not([data-theme="default"]) {
      --primary: oklch(var(--theme-l) var(--theme-chroma) var(--theme-hue));
      --ring: oklch(var(--theme-l) calc(var(--theme-chroma) * 0.85) var(--theme-hue));
      /* ...accent, secondary, chart-1..5 */
    }
  2. 2

    Register the themes

    List them once in lib/themes.ts. The provider, the switcher and the flash-prevention script all read from this array.

    lib/themes.ts
    export const colorThemes = [
      { id: "default", label: "Default", description: "Neutral zinc" },
      { id: "red",     label: "Red",     description: "Bold and energetic" },
      { id: "blue",    label: "Blue",    description: "Trustworthy classic" },
    ] as const
  3. 3

    Wrap your app and drop in the switcher

    ThemeProvider composes next-themes with the color layer. ThemeSwitcher goes anywhere inside it.

    tsx
    // app/layout.tsx
    <html lang="en" suppressHydrationWarning>
      <body>
        <ThemeProvider>{children}</ThemeProvider>
      </body>
    </html>
    
    // anywhere in the tree
    <ThemeSwitcher />
    
    // or read / set it yourself
    const { colorTheme, setColorTheme } = useColorTheme()