1. Getting started
  2. Guides
  3. Dark mode

Dark mode

Learn how to implement dark mode in your project.

Learn how to implement dark mode in your project.

Frameworks

Install next-themes

npm install next-themes

Create a theme provider

components/theme-provider.tsx
"use client";
 
import * as React from "react";
import { ThemeProvider as NextThemesProvider } from "next-themes";
 
export function ThemeProvider({
  children,
  ...props
}: React.ComponentProps<typeof NextThemesProvider>) {
  return <NextThemesProvider {...props}>{children}</NextThemesProvider>;
}

Wrap your root layout with ThemeProvider

app/layout.tsx
import { ThemeProvider } from "@/components/theme-provider";
 
export default function RootLayout({ children }: RootLayoutProps) {
  return (
    <>
      <html lang="en" suppressHydrationWarning>
        <head />
        <body>
          <ThemeProvider
            attribute="class"
            defaultTheme="system"
            enableSystem
            disableTransitionOnChange
          >
            {children}
          </ThemeProvider>
        </body>
      </html>
    </>
  );
}