ThemeProvider

⚠️ Most apps don't need ThemeProvider but will benefit from ThemeController. You generally only need ThemeProvider to apply a different theme to a subsection of your app or to snoop the CSS variables into JavaScript variables.

ThemeProvider is a special use component for applying DaisyUI theme variables and attributes to any part of your app. It parses DaisyUI plugin theme strings, applies CSS variables as inline styles, and sets non-variable attributes as data attributes.

The theme prop lets you specify a named theme that you have pre-programmed in your DaisyUI config. If you also provide the cssVars prop, its values will override the named theme, allowing for granular customization or one-off theme adjustments.

You can nest multiple ThemeProvider instances. Whichever ThemeProvider is the closest parent to a given element in the DOM will control the theme for that section, ensuring precise and predictable theme scoping.

This enables dynamic theme switching, dark/light mode support, and granular theme customization for your components or app sections.

Basic Example

Basic ThemeProvider

This section uses the some-custom theme.

Code Example
Basic.vue

ThemeProvider

The ThemeProvider component is the context provider for DaisyUI themes. It parses theme strings, applies variables and data attributes, and provides a reactive theme context to all descendants via both slot props and Vue's inject API. Supports dynamic switching, dark/light mode, and custom meta attributes.

ThemeProvider Props Type Description
dataTheme
string

Optional theme name. Sets the data-theme attribute unless a name: property is present in cssVars, in which case the name value takes precedence.

cssVars
string

The DaisyUI theme string in plugin format. CSS variables and meta attributes are parsed and applied to the subtree. If the string contains a name: property, it will override the dataTheme prop for the data-theme value.

snoop
boolean

When enabled, provides live CSS variable values as computed from the rendered element and updates them reactively. Useful for theme editors, previews, and debugging.

ThemeProvider Slots Description
default

The default slot. Content will receive the theme context and styling. Slot props include the current theme variables and a utility to generate DaisyUI theme strings.

ThemeProvider Provides Type Description
slotData
object

The computed theme context object, always reactive. Contains both the vars object (theme variables) and the toThemeString function. Provided via Vue inject API and as slot props.

vars
object

The current DaisyUI theme variables as a flat object. When snoop is enabled, these are computed from the live DOM; otherwise, parsed from the theme string.

toThemeString
Function

Utility function to convert the current theme variables to a DaisyUI theme string (plugin format). Useful for theme editors, export, or debugging.

parsed
object

The parsed structure containing style, dataAttrs, and dataTheme for the current theme string. Used internally and available for advanced use cases.

Examples

Dark Mode

Provide a theme string with color-scheme: "dark"; and prefersdark: true; to enable dark mode for the subtree.

Dark Mode ThemeProvider

This section uses the night theme in dark mode.

Code Example
DarkMode.vue

Custom Attributes

Add custom meta attributes (like radius, border, etc.) to further customize the theme context.

Custom Attributes

This section uses a theme with custom attributes like --radius-selector and --noise.

Code Example
CustomAttributes.vue

Dynamic Switching

Switch between light and dark themes at runtime.

Dynamic Theme Switching

The theme switches between susinferno (light) and night (dark).

Code Example
DynamicSwitching.vue

Dynamic Switching (Snoop)

Switch between light and dark themes and snoop the DaisyUI variables in real time.

Dynamic Theme Switching (Snoop)

The theme switches between light and dark.

Current themeVars:

{
  "vars": {}
}

Code Example
DynamicSwitchingSnoop.vue

Snoop

Snoop ThemeProvider

This demo uses snooping to read DaisyUI variables from the current theme.

{}
Code Example
Snoop.vue

Snoop to Theme String

Show the DaisyUI theme string generated from the snooped variables using toThemeString.

Snoop to Theme String

This demo uses snooping to read DaisyUI variables from the current theme and outputs the theme string.

@plugin "daisyui/theme" {

}
Code Example
SnoopToThemeString.vue

Theme Selection

Theme Selector

Current theme: light

Try changing the theme using the select above. The card colors update live.

Code Example
ThemeSelect.vue

Inject

See how to inject a theme string into the component tree using Vue's inject API.

Theme Selector (Injected)

This demo uses the inject API to access the theme context.

{}
The toThemeString function is also available for child components.
Code Example
ThemeInject.vue