Migration to v4 css based config #13813
-
I was having fun learning TailwindCSS v4 by trying to translate our company's current TailwindCSS config to a v4 CSS-based config. My first question is, how do we separate colors in Tailwind CSS v4? Using a JavaScript-based config, I could specify colors as backgroundColors, borderColors, and stroke separately. What's the equivalent of this in v4? Could you provide an example? Also, how can I define my colors for both dark and light modes in the same config file using CSS variables? I was exploring the default theme on GitHub. Are we saying these are the only things customisable by now? I added a css variable |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The equivalents are:
You could consider using the @import "tailwindcss";
@theme {
--color-foo: light-dark(white, black);
} Or you could use the @import "tailwindcss";
@theme {
--color-foo: white;
}
@media (prefers-color-scheme: dark) {
:root {
--color-foo: black;
}
} Although do be aware that the maintainers don't really recommend this approach: For example, from Simon Vrachliotis:
And from Adam Wathan:
|
Beta Was this translation helpful? Give feedback.
The equivalents are:
backgroundColor.key
--background-color-<key>: <value>
borderColor.key
--border-color-<key>: <value>
See this Tailwind Play
You could consider using the
light-dark()
function like:Or you could use the
prefers-color-scheme
media query like: