Skip to main content

Overview

While Uniwind provides light and dark themes by default, you can create unlimited custom themes for advanced use cases. Custom themes are perfect for branding variations, seasonal themes, accessibility modes, or any scenario where you need more than two color schemes.
Custom themes work exactly like the default themes, with full support for theme switching and CSS variable management.

Creating a Custom Theme

Creating a custom theme involves two steps:
  1. Define theme-specific CSS variables in global.css
  2. Register the theme in metro.config.js

Step 1: Define Theme Variables in global.css

Add your custom theme using the @variant directive. All themes must define the same set of variables.
Important: Every theme must define the same CSS variables. If you add a variable to one theme, add it to all themes. Uniwind will warn you in __DEV__ mode if variables are missing.

Example: Adding a “Premium” Theme

global.css

Step 2: Register Theme in metro.config.js

Add your custom theme to the extraThemes array in your Metro configuration:
metro.config.js
After adding a new theme, restart your Metro bundler for the changes to take effect.

Step 3: Use Your Custom Theme

Switch to your custom theme programmatically:

Complete Example: Multiple Custom Themes

Here’s a complete example with multiple custom themes for different use cases:

global.css with Multiple Themes

global.css

metro.config.js with Multiple Themes

metro.config.js

Theme Switcher Component

Create a theme switcher that includes your custom themes:
ThemeSwitcher.tsx

Best Practices

Keep variable names consistent: Use the same variable names across all themes. This ensures components look correct regardless of the active theme.
Test all themes: Always test your UI with every theme to ensure proper contrast and readability.
Use OKLCH for better colors: Consider using OKLCH color space for more perceptually uniform themes. See the Global CSS guide for details.
Don’t forget to restart Metro: Changes to metro.config.js require a Metro bundler restart to take effect.

Troubleshooting

Theme not appearing

  1. Check that the theme is registered in extraThemes array
  2. Verify all CSS variables are defined in the @variant
  3. Restart Metro bundler
  4. Clear Metro cache: npx expo start --clear

Missing styles

  1. Ensure all themes define the same set of CSS variables
  2. Check for typos in variable names
  3. Look for warnings in __DEV__ mode about missing variables

Theming Basics

Learn the fundamentals of theming in Uniwind

Global CSS

Configure global styles and CSS variables

Update CSS Variables

Dynamically update CSS variables at runtime

useUniwind Hook

Access theme information in your React components

Style Based on Themes

Advanced theme-based styling techniques