Using both media and class for dark mode #3644
Replies: 3 comments 11 replies
-
There is no way for TailwindCSS to achieve that behavior. They also can't really do it without massively bloating the CSS file. I would solve this programmatically. I for example use the next-themes package in my Next.js project to achieve this behavior. What tech stack do you work with? Perhaps I could help you find a fitting package. |
Beta Was this translation helpful? Give feedback.
-
We need something like this: `dark:${cssClass} [@media(prefers-color-scheme:dark)]:[&:not([data-theme]_&)]:${cssClass}` (for when we configured tailwind as |
Beta Was this translation helpful? Give feedback.
-
Even easier:
Call it after you load, and then toggle the initial theme. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to set my website theme based on user preference (
prefers-color-scheme
). So I configuredmedia
in thedarkMode
config. But I'd also like to let the user override this and force light theme (if the system one is dark).How can I use both
media
andclass
? Thanks!As @trm217 answered, there is no way to use both natively for the moment. Hope this will change in the futur.
Beta Was this translation helpful? Give feedback.
All reactions