Using custom properties for colors #3099
Replies: 2 comments 2 replies
-
It sounds like you want to manually toggle dark mode by changing a single container class. I think that is already supported. That said, there are other scenarios where you may want to "theme" an app—that is, toggle a single parent class and have it change many colors. I think CSS variables are a good way to do that, and I proposed adding official Tailwind support in #1978. The Tailwind team decided not to implement it, but it is possible to implement yourself. |
Beta Was this translation helpful? Give feedback.
-
Hey, Yep, that's a valid way to go around it if you need to support more "themes" and not only the built in You can see a simple example that Adam did a fair while ago, which takes the exact approach you are talking about. It uses custom properties for colors in the config file, and then redefines these properties for each theme, scoped in a class name. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm guessing it can't be so clean and simple so here is my question.
I'm planning into using CSS custom properties for defining colors and apply different themes to it e.g.
I've done a quick test extending tailwind.config.js like the following and it apparently works:
So I can later use regular tailwind classes like
bg-card
orcolor-card
and switch the color by a container classt-dark
.Is there any reason for not doing this? any alternatives?
I am also thinking if this could be a way of handling the "dark" mode without the suggested
dark:
classes approach... but probably you guys have also thinked about it and there should be a good reason for not doing it so.Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions