@utility not working in Tailwindcss v4 #17912
-
|
I just migrated Tailwindcss from v3 to v4. I then tried adding some custom utility classes. For that, I created an
@reference "../app/globals.css";
@utility widget-card-header {
@apply sticky top-0 font-proxima rounded-t-lg bg-slate-950 text-white p-4!;
}
@import "tailwindcss";
@import url("../styles/app.utilities.css") layer(utilities);
@custom-variant dark (&:is(.dark *));
@theme {...}
@layer base {...}When I now apply that utility class to my component, for some reason it is no applied. <div class="font-semibold leading-none tracking-tight widget-card-title">Top Tags</div> |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hey! The If you want to use custom utilities, you have to move the That said you are defining - widget-card-header
+ widget-card-title |
Beta Was this translation helpful? Give feedback.

Hey!
The
@referenceallows you to reference your custom theme, which means that you can use features like custom@utilityor@applywith@themevalues defined in the referenced file.The reference is also just that, a reference.
If you want to use custom utilities, you have to move the
@utilitydefinition to the referenced file. In your case, move it to theapp/globals.cssfile.That said you are defining
widget-card-headerand usingwidget-card-title