Dark Mode
Overview
Dark mode works out of the box in this starter kit. The default theme is system. It's based on next-themes and shadcn/ui's dark mode.
How to use
Styles and theme
The styling is in the src/app/globals.css
file. All the light mode styling is directly specified :root
selector while the styles of dark mode are under .dark
class.
Default theme
The default style is system preference right now. It can be changed very easily by changing the value of defaultTheme
prop in <ThemeProvider>
tag in src/app/layout.tsx
file.
Mode toggle
The starter kit comes with a toggle button as well. It's src/components/ModeToggle.tsx
file.
To use it, simple import in whatever file you want to show it and use it as a regular component.
I have used it myself in the kit home page, check out for reference: https://github.com/inclinedadarsh/nextjs-starter/blob/7160b806e22ffbcf166fd4a62f9c8477ecfacde9/src/app/page.tsx#L50C1-L50C25
Arbitrary use
If you want to use styles in your components that are not specified in globals.css
, you can do that using the dark:
variant of TailwindCSS.
Other resources
Custom styles: Custom styles
Next Themes: https://www.npmjs.com/package/next-themes
Shadcn/UI's dark mode docs: https://ui.shadcn.com/docs/dark-mode/next
TailwindCSS' dark mode docs: https://tailwindcss.com/docs/dark-mode
Last updated