Skip to Content
ComponentsThemeProvider

ThemeProvider

ThemeProvider stores the active theme and writes the matching data-theme attribute on the document element by default.

Props

PropTypeDefaultDescription
defaultThemeThemeId'windows-98'Initial theme.
storageKeystring | null'murasaki-theme'Local storage key. Use null to disable persistence.
attributeTargetHTMLElement | nulldocument.documentElementOptional element that receives data-theme instead of <html>.
childrenReactNoderequiredThe app subtree.

Examples

Theme switcher

Active theme:windows-98

ARIA

ThemeProvider has no own UI. Ensure color contrast remains acceptable for custom theme variables.

Keyboard

ThemeProvider has no UI and no keyboard behavior.

SSR

For SSR apps, pass a request-aware defaultTheme when possible. Use storageKey={null} for isolated previews and examples.

Last updated on