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
TheThemeProvider is automatically included when you install the theme system:
Usage
Wrap your application with theThemeProvider in your root layout:
app/layout.tsx
Implementation
TheThemeProvider is a thin wrapper around next-themes with pre-configured settings optimized for the tweakcn theme system:
components/theme-provider.tsx
Configuration
TheThemeProvider uses the following configuration from next-themes:
The HTML attribute used to apply themes. Sets
data-theme="{theme-name}" on the root element.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", ...]).The theme applied on first load before any user selection. Can be customized by importing and using
DEFAULT_THEME from @/lib/themes-config.System preference detection is disabled because tweakcn themes handle both light and dark modes internally. Each theme exists as separate
-light and -dark variants.Prevents CSS transitions during theme changes to avoid visual flash and improve perceived performance.
Props
Your application content that will have access to theme functionality.
Theme Values
The provider automatically loads all installed themes fromthemes-config.ts. Each theme has two variants:
{theme-name}-light- Light mode variant{theme-name}-dark- Dark mode variant
default-darkcatppuccin-lightcyberpunk-darkvercel-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
Related
ThemeSwitcher
Add a dropdown UI for selecting themes
useTheme Hook
Control themes programmatically