How it Works
Dark mode in shadcn/ui works by:- Adding a
.darkclass to the root element - Applying different CSS variable values under the
.darkselector - Components automatically adapt based on the active theme
Framework Integration
- Tab Title
- Tab Title
- Tab Title
- Tab Title
Next.js
For Next.js applications, use thenext-themes package.Customizing Dark Mode Colors
Customize dark mode colors by modifying the.dark selector in your CSS:
app/globals.css
All color variables in the
.dark selector override the light mode values when dark mode is active.System Preference
Most theme providers support automatic detection of the user’s system preference:Preventing Flash of Wrong Theme
For Next.js:- Use
suppressHydrationWarningon the<html>tag - The
next-themespackage handles this automatically
- Add an inline script in the
<head>to set the theme class before rendering - This script should run synchronously before the page renders