Follow the steps below to add dark mode to your Next.js application using Tailwind CSS
Install Tailwind
If you don't have Tailwind already installed, run the following command to install it and its dependencies.
Run the init command to generate both tailwind.config.js and postcss.config.js.
Add the paths to all of your template files in your tailwind.config.js file.
Add the @tailwind
directives at the top of your globals.css file.
Initial setup
setup the darkMode strategy to class in the tailwind.config.js file
Install next-themes
Create a theme provider
Wrap your root layout
add the following to your global.css
Adding a toggle button
Done! Try it out!