Menu

How to Apply Multiple Themes in Next.js (Blue, Green, Red and More) Without Refreshing or Using `dark:` Classes
📰

How to Apply Multiple Themes in Next.js (Blue, Green, Red and More) Without Refreshing or Using `dark:` Classes

DEV Community: nextjs·Muhammad Hamid Raza·8 days ago
#WRukZrMq
#devtonextjs#devto#dev#dbeafe#theme
Reading 0:00
15s threshold

Your site has a dark mode. Then a client asks, "Can we also have a blue theme? And a green one? Oh, and red!" 😅

Suddenly you are staring at dark:bg-gray-900 blue:bg-blue-900 green:bg-green-900 red:bg-red-900 on every element. That is a lot of repeated classes.

There is a cleaner way. You define every theme's colors once in your global CSS. To switch themes, you change one class on the <html> element. No page refresh, no HTML changes, no per-element theme classes.

Ready to see how it works? 🚀

What Is a Multi-Theme System in Next.js?

A multi-theme system lets users switch between more than two color schemes, such as light, dark, blue, green, and red. The switch happens instantly, with no reload.

Think of a TV remote . The TV (your HTML) stays exactly the same.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.