Dark Mode Configuration
Dark mode is configured innuxt.config.ts with the @nuxtjs/color-mode module:
classSuffix: '' option means the dark mode class is simply dark instead of dark-mode.
Tailwind Dark Mode
Tailwind is configured to use class-based dark mode intailwind.config.js:
dark class is present on a parent element (typically <html> or <body>).
Dark Mode Toggle
The dark mode toggle is implemented in the navbar (components/layout/Navbar.vue:84-103):
Using Dark Mode in Components
Apply dark mode styles using thedark: prefix in Tailwind classes:
Common Dark Mode Patterns
Background Colors
Fromapp.vue:11:
Text Colors
Frompages/index.vue:90-93:
Card Backgrounds
Fromcomponents/misc/Projects.vue:219:
Icons and Accents
Frompages/index.vue:180-182:
Customizing Dark Mode Colors
Create a consistent dark mode palette by extending your Tailwind config:Color Mode Composable
Access the color mode in your components using the composable:System Preference
By default, Nuxt Color Mode respects the user’s system preference. You can configure this:Transition Effects
Add smooth transitions when switching between modes:Dark Mode Images
For images that need different versions in light/dark mode:Testing Dark Mode
Test your dark mode implementation:- Toggle using the navbar button
- Check browser DevTools for the
darkclass on<html> - Test with system dark mode enabled
- Clear localStorage and refresh to test default preference
Debugging Tips
- Check if the
darkclass is being applied to the HTML element - Ensure Tailwind dark mode is set to
'class'not'media' - Verify
@nuxtjs/color-modeis in the modules array - Check browser localStorage for
nuxt-color-modekey - Use browser DevTools to inspect computed styles