SwipeUI
DocsTheming & motion

Dark mode

Light and dark themes with Uniwind, and how to switch between them.

init writes every colour token twice, once per theme, inside Uniwind's theme block:

swipeui-theme.css
@layer theme {
  :root {
    @variant light {
      --color-background: #f8fafc;
      /* … */
    }
    @variant dark {
      --color-background: #0b1020;
      /* … */
    }
  }
}

Components only use the token classes, so they change with the theme. None of them check the colour scheme themselves.

Following the system or choosing a theme

With ThemeProvider, use useTheme().setScheme('dark') or the ready-made Theme switch, listed under Buttons, so named presets and system tracking stay coordinated. Without the provider, base themes can use Uniwind directly:

components/theme-toggle.tsx
import { Uniwind } from 'uniwind';

Uniwind.setTheme('dark'); // 'light', 'dark' or 'system'

Gotchas

  • Keep both themes complete. A token defined only for light falls back to nothing in dark. npx @swipeui/cli doctor lists missing tokens.
  • Check contrast in both themes when you change colours: text and icons need WCAG AA against their background.
  • Glass surfaces are untinted Liquid Glass (tinted adds glass-tint), and fall back to surface-elevated when Reduce Transparency is on (see use-reduce-transparency).

On this page