Replies: 2 comments 4 replies
|
Hey! For places where CSS variables don't work sense, we still have the theme function. You'd use it like |
|
You mention that I couldn't find any mention of deprecation in the docs, upgrade guide, or release notes. Personally, I still see a few advantages to
Did the Tailwind team officially recommend moving away from EDIT:Beyond autocomplete and validation, I think For example: :root {
--token: blue;
}
@theme {
--foo: var(--token);
}
.theme-a {
--token: red;
}If we write: .foo {
color: theme(--foo);
}the generated CSS is effectively: .foo {
color: var(--token);
}As a result, However, if we write: .foo {
color: var(--foo);
}then :root {
--foo: var(--token);
}and the browser resolves So This can be useful when theme tokens are composed from other variables that may vary depending on context. In those cases, |

Uh oh!
There was an error while loading. Please reload this page.
Why is the theme() function in v4 deprecated? Using only CSS variables makes no sense to me with the use of Lightning CSS. Especially with regard to the mathematical functions of CSS.
One great thing about Lightning CSS is that it can simplify the mathematical functions of CSS. But unfortunately only if no CSS variables are used.
https://lightningcss.dev/transpilation.html#math-functions
Here is an example of a fluid spacing calculation with CSS variables:
CSS Configuration:
var-test-px-20 compiles to:
Here is an example of a calculation of the fluid spacing with theme():
CSS Configuration:
theme-test-px-20 compiles to:
The difference is impressive, isn't it? The root variables are also not required and can therefore be omitted with ‘@theme reference{}’ in the final CSS file. If you still need the CSS variables, you can also create them again in the CSS configuration under ‘’@theme‘’.
And here is another example of the general spacing behaviour of Tailwind v4:
I also wonder why a CSS variable has to be used here.
Here is the compiled code for e.g. px-4:
And here is a customised version for e.g. px-4 with theme():
Why doesn't it work the same way? It's better than inserting the CSS variable every time. There is also no disadvantage because I still have access to a global spacing variable via the CSS configuration. For those who need the CSS variable, an optional function should be available.
What do you think?
All reactions