Basic Color Modes Setup
Define color modes in your theme:The useColorMode Hook
Use theuseColorMode hook to read and update the current color mode:
Color Mode Provider
Wrap your app withColorModeProvider:
Configuration Options
initialColorModeName
Set the default color mode:useColorSchemeMediaQuery
Detect the user’s system preference:false(default): Don’t detect system preferencetrueor'initial': Detect on initial load only'system': Always follow system preference with live updates
useLocalStorage
Persist color mode to localStorage:false to disable persistence:
printColorModeName
Set a specific color mode for printing:useCustomProperties
Enable or disable CSS custom properties (CSS variables):false for legacy browser support (IE11):
Multiple Color Modes
Define multiple color modes beyond just light and dark:Media Query Detection
Theme UI automatically detects theprefers-color-scheme media query:
Example: Complete Color Mode Setup
Here’s a complete example from the Theme UI source:Accessing Color Values
When using CSS custom properties (default), colors are converted to CSS variables:When
useCustomProperties is enabled, use theme.rawColors to access the original color values, as theme.colors will contain CSS custom property references.