Last updated on March 30, 2026
Dynamic Themes
Nativewind v5 supports dynamic theming through CSS variables and the VariableContextProvider component. This lets you change colors, spacing, and other design tokens at runtime without rebuilding your stylesheet.
For static theme customization (adding custom colors, fonts, spacing), see the Theme documentation. For dark mode specifically, see Dark Mode.
How It Works
- Define CSS variables in your
global.cssusing@themeand:root - Reference those variables in your utility classes (e.g.
bg-primary,text-secondary) - Override the variables at runtime using
VariableContextProvider
The provider uses React context, so any component wrapped by it (and its children) will pick up the overridden values.
Basic Example
First, define your theme variables in CSS:
You need to define the variables in both @theme (so Tailwind generates the utility classes) and :root (so the CSS variables have default values at runtime).
Then override them at runtime:
Multiple Themes with Light/Dark Mode
Combine VariableContextProvider with useColorScheme from react-native to support multiple themes that each have light and dark variants:
Nesting Themes
VariableContextProvider inherits from its parent context. You can nest providers to override specific variables while keeping the rest:
Migrating from v4
If you used vars() in v4, replace it with VariableContextProvider:
vars() is deprecated and will be removed in a future release.
Platform-Specific Theme Values
Use CSS media queries to set platform-specific defaults:
These can still be overridden at runtime via VariableContextProvider.