Dark Mode Setup
This guide shows how to implement dark mode using CSS variables and system preferences.
Automatic dark mode
UI Lab components automatically support dark mode via CSS variables. Enable it by:
Components respond to system preference automatically via prefers-color-scheme. No additional setup needed.
Manual theme toggle
Control theme programmatically:
Update CSS variables
Override color variables for your theme. Add to your root CSS file or globals.css:
Persist user preference
Save theme choice and restore it on page load:
Use in your app
Color scale reference
All color variables automatically invert in dark mode:
| Variable | Light | Dark |
|----------|-------|------|
| --background-50 | White | Near black |
| --background-100 | Off-white | Very dark |
| --foreground-950 | Near black | White |
| --foreground-900 | Very dark | Off-white |
| --color-primary | Adjusted for light | Adjusted for dark |
Next step
Learn to combine dark mode with forms in Build a Form with Validation.