Custom theme variables not working in media queries for custom variants #17841
-
What version of Tailwind CSS are you using? v4.1.5 What build tool (or framework if it abstracts the build tool) are you using? Tailwind Play What version of Node.js are you using? Tailwind Play What browser are you using? Firefox, Chrome What operating system are you using? Ubuntu Reproduction URL https://play.tailwindcss.com/IeRkVmIgty?file=css Describe your issue In the linked reproduction, when the viewport is smaller than the md breakpoint, both the square and the circle should change colors. But only the square is working. I am defining two custom variants using exactly the same syntax, but it doesn't work with my custom variable ( I have defined my custom variable under |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey! Unfortunately in CSS you can't use CSS variables in media queries like that. That's one of the reasons why you have to use If you use .small-md\:bg-green-300 {
@media (width >= 48rem) {
background-color: var(--color-green-300);
}
} For your custom variable, you use .small-custom\:bg-green-500 {
@media (width >= var(--breakpoint-md)) {
background-color: var(--color-green-500);
}
} If you really want a custom name and re-use an existing value, then you can also do this: @theme {
--breakpoint-custom: theme(--breakpoint-md);
} Notice how we use Play: https://play.tailwindcss.com/1pP6Mf7Zrf?file=css Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey!
Unfortunately in CSS you can't use CSS variables in media queries like that. That's one of the reasons why you have to use
theme(…)
to inline the value.If you use
theme(--breakpoint-md)
we inline it to the value of the--breakpoint-md
variable which maps to 48rem. That's what you can see here:For your custom variable, you use
theme(--breakpoint-custom)
which does give you the value for the--breakpoint-custom
, but that value is another CSS variable which is not supported, that's why you see: