Prerequisites
Before setting up dark mode, ensure you have:- Installed Subframe in your project
- Synced your components and theme to your codebase
How it works
- Configure Tailwind to use CSS variables instead of hardcoded colors
- Define light mode colors from your Subframe theme as CSS variables
- Define dark mode color overrides under an
html.darkselector - Toggle between modes by adding/removing the
darkclass on the HTML element
Step 1: Configure Tailwind for CSS variables
- Tailwind v3
- Tailwind v4
Modify your
tailwind.config.js to use CSS variables.Add
// @subframe/sync-disable at the top to prevent Subframe from overwriting your changes.tailwind.config.js
Find your theme configuration in the Theme
tab.
Step 2: Create CSS variables file
Create avariables.css file that defines CSS variables for both light and dark modes:
variables.css
Step 3: Import variables globally
Import yourvariables.css in your global CSS file (typically index.css, globals.css, or App.css depending on framework):
globals.css
main.tsx
Step 4: Toggle dark mode
Add or remove thedark class on the <html> element to switch themes.
Next.js with next-themes
app/layout.tsx
React with context
ThemeProvider.tsx
Theme toggle button
Best practices
Test both modes
Test both modes
Always test your application in both light and dark modes. Check for:
- Sufficient contrast ratios (use browser DevTools)
- Readability of all text
- Visibility of borders and dividers
- Proper styling of interactive states
Respect system preferences
Respect system preferences
Use the user’s system preference as the default:

