Skip to main content
The ThemeProvider component manages theme state including dark mode, light mode, and system preference. It includes the ThemeSwitcher component for toggling themes and the useTheme hook for accessing theme state.

Usage

Theme configuration

Custom themes

ThemeSwitcher

A pre-built component for toggling between light and dark themes.

useTheme hook

Access and control theme state from any component.

Forced theme

Force a specific theme for certain pages or components.

Disable transitions

API reference

ThemeProvider

string
default:"system"
The default theme to use. If enableSystem is false, defaults to ‘light’.
string[]
default:"['light', 'dark']"
List of all available theme names.
string
Force a specific theme for the current page or component tree.
boolean
default:"true"
Whether to enable system theme preference (prefers-color-scheme).
boolean
default:"true"
Whether to indicate to browsers which color scheme is used for built-in UI elements.
boolean
default:"false"
Disable all CSS transitions when switching themes to prevent flickering.
string
default:"theme"
Key used to store theme setting in localStorage.
string | 'class'
default:"data-theme"
HTML attribute modified based on the active theme. Accepts ‘class’ or any data attribute like ‘data-theme’, ‘data-mode’, etc.
object
Mapping of theme name to HTML attribute value. Object where key is theme name and value is the attribute value.
'modern' | 'traditional'
default:"modern"
Style variant of the theme. Affects radius and font properties.
'indigo' | 'orange' | 'mint'
default:"indigo"
Accent color for the theme.
'gray' | 'mauve' | 'slate'
default:"gray"
Gray color variant for the theme.
string
Nonce string to pass to the inline script for CSP headers.

ThemeSwitcher

number
default:"30"
Size of the theme toggle icon in pixels.

useTheme

Returns an object with the following properties:
string
The active theme name.
(theme: string) => void
Function to update the theme.
string[]
List of all available theme names.
string | undefined
The forced theme for the current page, if any.
string
If enableSystem is true and the active theme is ‘system’, this returns the resolved system preference (‘dark’ or ‘light’). Otherwise, identical to theme.
'dark' | 'light' | undefined
If enableSystem is true, returns the system theme preference, regardless of the active theme.