Description
Tailwind CSS v4.0 @apply
Bug Report
Introduction
I'm in the process of upgrading a large project, actually, five Blazor projects that all conjoin into one via components and different backends. Our focus with this project is to deliver an optimal UI experience to the end-user, which is why we use TypeScript, C#, and of course, our favorite, Tailwind CSS. Btw, huge fans!
Now, with that said, we have certain native components where we cannot add CSS classes to the component itself, making @apply
an essential part of our workflow. However, after upgrading to Tailwind CSS v4.0, @apply
is no longer working as expected, and there seems to be little guidance on how to transition projects that rely on it. This bug report aims to outline the issue clearly and request either a fix or detailed documentation on what exactly we need to do to overcome this.
What version of Tailwind CSS are you using?
v4.0.0
What build tool (or framework if it abstracts the build tool) are you using?
Webpack 5.97.1
What version of Node.js are you using?
v20.11.1
What version of npm are you using?
v10.7.0
What IDE are you using?
Rider IDE
What operating system are you using?
macOS
Reproduction URL
There's an active discussion on this issue where many developers are experiencing the same problem but no one has officially reported it yet. Rather than debating, I’d rather get a solution, so here’s the link to the discussion: #13336 (comment)(https://github.com/yourusername/tailwind-v4-apply-issue)
Describe your issue
After upgrading to Tailwind CSS v4.0, I encountered the following issues:
1. @apply
Directive Not Functioning
-
The
@apply
directive, previously used extensively in our CSS for class composition, no longer functions as expected. -
Example:
.quickgrid thead th { @apply tw-bg-slate-100 dark:tw-bg-slate-800/70 tw-py-4; }
- This results in build errors indicating unknown utility classes such as:
Error: Cannot apply unknown utility class: tw-transform Error: Cannot apply unknown utility class: tw-table-auto
2. Lack of Clear Documentation for @apply
Usage in v4.0
- The v4.0 documentation does not provide explicit guidance on how to use the
@apply
directive in non-Vue projects. - One part of the documentation states that
@apply
should still work, but this is only relevant for Vue projects. - Another section in the documentation (CSS Modules Compatibility) suggests using CSS variables instead:
background: var(--color-blue-500);
- This is not an ideal solution because it significantly increases the workload, especially in large projects where
@apply
is heavily used.
- This is not an ideal solution because it significantly increases the workload, especially in large projects where
3. Backward Compatibility with tailwind.config.js
- The
tailwind.config.js
file appears to be deprecated or its usage has changed in v4.0 without clear documentation. - Projects relying on configurations such as
prefix: 'tw-'
are experiencing issues with styles not applying correctly.
4. @apply
is Necessary for Native Blazor QuickGrid Components
- In my case, I use
@apply
with Native Blazor QuickGrid components, where there is no alternative way to apply Tailwind classes. - The current documentation does not provide any solutions for frameworks outside of Vue.
Expected Outcome
- A fix for
@apply
so that it functions as expected in Tailwind CSS v4.0. - Clear documentation outlining the necessary steps to transition existing projects that rely on
@apply
. - An explicit guide on how
tailwind.config.js
should be updated for v4.0.
Thank you for your attention to this issue!