Installation
Install vartheme from npm. No peer dependencies required.
Basic Setup
Wrap your app with ThemeProvider. That's it.
1import { ThemeProvider, ThemeToggle } from 'vartheme'
3export default function App() {
5 <ThemeProvider mode="system" transitions>
Next.js App Router
getFOUCScript() prevents white flash before React hydrates. Always add it in <head>.
2import { getFOUCScript } from 'vartheme'
3import { ThemeProvider } from 'vartheme'
5export default function RootLayout({ children }) {
7 <html suppressHydrationWarning>
9 <script dangerouslySetInnerHTML={{ __html: getFOUCScript() }} />
12 <ThemeProvider>{children}</ThemeProvider>
useThemeContext Hook
Access and control the theme from any component inside ThemeProvider.
1import { useThemeContext } from 'vartheme'
3function MyComponent() {
15 return <button onClick={toggle}>{resolvedMode}</button>
Built-in Themes
5 beautiful built-in themes. Switch at any time.
2<ThemeProvider theme="default"> // purple
3<ThemeProvider theme="ocean"> // blue
4<ThemeProvider theme="forest"> // green
5<ThemeProvider theme="sunset"> // orange
6<ThemeProvider theme="rose"> // pink
9const { setTheme } = useThemeContext()
shadcn/ui + Radix Support
Full compatibility with shadcn/ui, Radix UI, DaisyUI and any design system.
2<ThemeProvider strategy={{ type: 'class' }}>
4// data-theme="dark" + class="dark" — both
5<ThemeProvider strategy={{ type: 'both' }}>
8<ThemeProvider strategy={{ type: 'data-attribute', attribute: 'data-mode' }}>
Custom Colors
Override any color statically or dynamically at runtime.
2<ThemeProvider colors={{ primary: '#EC4899', accent: '#F59E0B' }}>
5const { setColors } = useThemeContext()
6setColors({ primary: '#10B981' })
CSS Variables
vartheme auto-injects CSS variables on <html>. Use them anywhere.
2 background: var(--vt-surface);
4 border: 1px solid var(--vt-border);
8 background: var(--vt-primary);
Tailwind Plugin
Use vartheme CSS variables directly as Tailwind utility classes.
2import { varthemePlugin } from 'vartheme/tailwind'
5 plugins: [varthemePlugin],
9<div className="bg-vt-surface text-vt-text border border-vt-border">
10 <h1 className="text-vt-primary">Hello!</h1>
onThemeChange Callback
Get notified whenever the theme changes. Perfect for analytics.
2 onThemeChange={(mode) => {
4 analytics.track('theme_switch', { mode })
5 console.log('Theme changed to:', mode)