Skip to main content
The ThemeProvider component wraps your application to enable theme switching functionality. It must be placed at the root level to make themes available throughout your app.

Installation

The ThemeProvider is automatically included when you install the theme system:

Usage

Wrap your application with the ThemeProvider in your root layout:
app/layout.tsx
Add suppressHydrationWarning to the <html> tag to prevent hydration warnings when themes are applied.

Implementation

The ThemeProvider is a thin wrapper around next-themes with pre-configured settings optimized for the tweakcn theme system:
components/theme-provider.tsx

Configuration

The ThemeProvider uses the following configuration from next-themes:
string
default:"data-theme"
The HTML attribute used to apply themes. Sets data-theme="{theme-name}" on the root element.
string[]
default:"allThemeValues"
Array of all available theme values. Automatically generated from your installed themes, including both light and dark variants (e.g., ["default-light", "default-dark", "catppuccin-light", "catppuccin-dark", ...]).
string
default:"default-dark"
The theme applied on first load before any user selection. Can be customized by importing and using DEFAULT_THEME from @/lib/themes-config.
boolean
default:"false"
System preference detection is disabled because tweakcn themes handle both light and dark modes internally. Each theme exists as separate -light and -dark variants.
boolean
default:"true"
Prevents CSS transitions during theme changes to avoid visual flash and improve perceived performance.

Props

ReactNode
required
Your application content that will have access to theme functionality.

Theme Values

The provider automatically loads all installed themes from themes-config.ts. Each theme has two variants:
  • {theme-name}-light - Light mode variant
  • {theme-name}-dark - Dark mode variant
Examples:
  • default-dark
  • catppuccin-light
  • cyberpunk-dark
  • vercel-light

Customization

If you need to customize the provider configuration, you can modify the component:
components/theme-provider.tsx
The ThemeProvider must be a client component ("use client"). It uses React context and browser APIs that only work on the client side.

Next.js App Router

For Next.js 13+ with the App Router, place the provider in your root layout:
app/layout.tsx

Vite/React

For Vite or standard React apps, wrap your app in the main entry point:
src/main.tsx

ThemeSwitcher

Add a dropdown UI for selecting themes

useTheme Hook

Control themes programmatically