-
What's the recommended method for using CSS variables for color theming? As a basic example, take the following CSS v4 config which does not work (which you can also see here https://play.tailwindcss.com/V8n8xj1DFD?file=css): @import "tailwindcss";
@theme {
--color-primary: var(--primary);
}
@layer base {
:root {
--primary: red;
}
.blue {
--primary: blue;
}
} The goal is to have various classes which, when added to any element, change the variables and therefore the color styles of that element. However, the above does not work. I duplicated this in a non-tailwind project just using CSS layers and saw the same thing, which is super unfortunate as I was hoping it was specific to tailwind. What happens is if you inspect, the text in this tailwind play https://play.tailwindcss.com/V8n8xj1DFD?file=css , you should see the variable The best solution I've come up with at this point is to override the --color-primary variable itself. So the CSS will instead look like https://play.tailwindcss.com/yOEsY950qB @import "tailwindcss";
@theme {
--color-primary: red;
}
@layer base {
.blue {
--color-primary: blue;
}
} Is there a better method out there or something I'm missing? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Yes, you are missing the @import "tailwindcss";
@theme inline {
--color-primary: var(--primary);
}
@layer base {
:root {
--primary: red;
}
.blue {
--primary: blue;
}
} Though, your second method would seem like it could work well too. |
Beta Was this translation helpful? Give feedback.
Yes, you are missing the
inline
tag with@theme
(#14095):Your Play with this change.
Though, your second method would seem like it could work well too.