ThemeProvider
A wrapper aroundnext-themes ThemeProvider that configures theme management for the tweakcn Theme Picker system.
Located in
registry/nextjs/components/theme-provider.tsxComponent Signature
Props
ReactNode
required
React children to be wrapped by the theme provider. Typically your entire application tree.
Source Code
Configuration
The ThemeProvider is pre-configured with the following settings:attribute
string
default:"data-theme"
HTML attribute used to apply the theme. The current theme value is set on the root element as
data-theme="theme-name".themes
string[]
default:"allThemeValues"
Array of all available theme values. Includes both light and dark variants for all 45 themes (90 total values).Examples:
["default-light", "default-dark", "catppuccin-light", "catppuccin-dark", ...]defaultTheme
string
default:"default-dark"
Initial theme applied when no user preference exists in localStorage. Set to
"default-dark" for a dark-first experience.enableSystem
boolean
default:false
System theme detection disabled. Users must explicitly choose light or dark mode rather than following OS preferences.
disableTransitionOnChange
boolean
default:true
Prevents CSS transitions during theme changes to avoid visual glitches. Theme switches happen instantly.
Usage
App Router (Next.js 13+)
app/layout.tsx
Pages Router (Next.js 12)
pages/_app.tsx
How It Works
- Initialization: On mount, the provider reads the theme from localStorage or uses
DEFAULT_THEME - DOM Update: The theme value is set as
data-themeon the HTML element - Persistence: Theme changes are automatically saved to localStorage
- Context: Provides theme state and controls via the
useThemehook
HTML Output
CSS Integration
Themes are applied using CSS attribute selectors:globals.css
Client-Side Only
Dependencies
- next-themes: Theme management library (v0.2.1+)
- React: 18.0.0+
- Next.js: 13.0.0+ (for App Router) or 12.0.0+ (for Pages Router)
TypeScript Support
Fully typed with TypeScript. Thechildren prop is typed as ReactNode from React.
See Also
- useTheme - Hook for accessing theme state and controls
- ThemeSwitcher - UI component for theme selection
- allThemeValues - Complete list of theme values
- DEFAULT_THEME - Default theme constant
- next-themes Documentation - Underlying library