Tailwind v4 @apply unknown utility class error — custom classes used before defined #20211
Replies: 2 comments
-
|
The single pass is not the problem here. The issue is that you can only apply utilities defined with If you update your CSS file with that instead, then it will work. More info: https://tailwindcss.com/docs/upgrade-guide#adding-custom-utilities |
Beta Was this translation helpful? Give feedback.
-
|
In Tailwind CSS v4 (which is CSS-first), When you define a custom class using standard CSS layer nesting inside To fix this, you should use the new @utility p-16-regular {
@apply font-normal text-[16px] leading-[140%];
}
@utility wrapper {
@apply max-w-5xl mx-auto px-5 md:px-10 w-full text-dark-400 p-16-regular;
}This ensures the Tailwind compiler registers |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem:
In Tailwind v4, CSS is processed top to bottom in a single pass. If a custom utility class is used with @apply before it's defined in the file, the compiler throws an error. This is different from v3 which used a multi-pass system and didn't care about order.
I'm trying fix that by order them, but it still throw an error...
For example:
Error:
Cannot apply unknown utility class p-16-regular
Beta Was this translation helpful? Give feedback.
All reactions