Skip to main content

Overview

Uniwind provides two approaches for creating theme-aware styles: using theme variant prefixes (like dark:) or defining CSS variables with @layer theme. Each approach has its use cases and benefits.

Approach 1: Theme Variant Prefixes

The simplest way to style components based on themes is using the dark: variant prefix.

Basic Usage

By default, styles apply to all themes:
Add theme-specific styles using the dark: prefix:

Multiple Theme-Specific Styles

You can combine multiple theme-aware utilities:

When to Use Theme Variant Prefixes

Best for: One-off styling, prototyping, or small components where you want explicit control over light and dark mode colors.
Pros:
  • Explicit and easy to understand
  • No setup required
  • Full control over each theme’s appearance
  • Works great for small apps or prototypes
Cons:
  • Verbose for larger apps
  • Requires repeating dark: prefix for many properties
  • Difficult to maintain consistent colors across components
  • Doesn’t scale well to 3+ themes

Approach 2: CSS Variables with @layer theme

For larger applications, defining theme-specific CSS variables provides a more scalable and maintainable solution.

Setting Up CSS Variables

Define your theme variables in global.css:
global.css

Using CSS Variables

Reference your variables directly in components:
bg-background automatically resolves to #ffffff in light theme and #000000 in dark theme. No dark: prefix needed!

When to Use CSS Variables

Best for: Medium to large applications, design systems, or apps with consistent color palettes across many components.
Pros:
  • Clean, maintainable code
  • Consistent colors across the entire app
  • Easy to update themes in one place
  • Scales well to any number of themes
  • Semantic naming improves code readability
Cons:
  • Requires initial setup
  • Less explicit than variant prefixes
  • Need to define all variables upfront

Supporting Multiple Themes

CSS variables make it easy to support unlimited custom themes:
global.css
Components using these variables automatically work with all themes:
To register additional themes, follow the Custom Themes guide.

Migration Guide

From Theme Variants to CSS Variables

  1. Identify repeated colors across your components
  2. Define CSS variables for these colors in global.css
  3. Replace theme variants with CSS variable references
  4. Test thoroughly in all themes
Example migration:

Theming Basics

Learn the fundamentals of theming in Uniwind

Global CSS

Configure global styles and CSS variables

Custom Themes

Create custom themes beyond light and dark

useUniwind Hook

Access theme information in your components