{"@context":"https://schema.org","@graph":[{"@type":"TechArticle","headline":"Next.js","description":"Make your Next.js app dark mode ready with a smooth, step by step guide to set up theme switching, persist preferences, and polish the experience across pages.","url":"https://intentui.com/docs/dark-mode/next-js","author":{"@type":"Person","name":"Irsyad","url":"https://x.com/irsyad"},"publisher":{"@type":"Organization","name":"Intent UI","url":"https://intentui.com","logo":{"@type":"ImageObject","url":"https://intentui.com/icon.svg"}},"mainEntityOfPage":{"@type":"WebPage","@id":"https://intentui.com/docs/dark-mode/next-js"}},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://intentui.com"},{"@type":"ListItem","position":2,"name":"Docs","item":"https://intentui.com/docs"},{"@type":"ListItem","position":3,"name":"Dark mode","item":"https://intentui.com/docs/dark-mode"},{"@type":"ListItem","position":4,"name":"Next.js","item":"https://intentui.com/docs/dark-mode/next-js"}]}]}
Dark mode
Next.js
Make your Next.js app dark mode ready with a smooth, step by step guide to set up theme switching, persist preferences, and polish the experience across pages.
Because you are using Next.js, you can use next-themes to implement dark mode. And since you're using @heroicons/react, you can use the SunIcon and MoonIcon icons.
npm
pnpm
yarn
bun
npm install next-themes @heroicons/react
Provider and switcher
Next, you need to create a theme provider component. You can do it like this:
Loading source code...
Usage
After that, you can use it in your root layout file like so:
import { Providers } from '@/components/providers'export default function RootLayout({ children }: Readonly<{ children: React.ReactNode }>) { return ( <html lang="en" suppressHydrationWarning> <body> <Providers> {children} </Providers> </body> </html> )}