[TailwindCSS V4] Cannot apply utility class ... (In the style tag)
Heya! I'm working on a component using Tailwind CSS, and I’m running into this error:
Here’s my component code for context:
Does anyone know why Tailwind is complaining about md:flex? Is there something I might have misconfigured?
8 Replies
Hi @Fedox. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The error message:
indicates that the
See the section on customizing breakpoints and the CSS-first configuration approach in the Nuxt UI theming guide: Theme customization with @theme. If you’re using a custom setup or have removed the default breakpoints, re-add them as shown above. This should restore the
md
(medium breakpoint) variant is not available in your Tailwind CSS configuration. In Tailwind CSS v4 (as used by Nuxt UI), breakpoints and other design tokens are now defined using CSS variables inside a @theme
directive in your CSS, rather than in a JavaScript config file. If you haven't defined the md
breakpoint in your theme, Tailwind won't generate the corresponding utilities like md:flex
.
How to fix:
You need to ensure that your main.css
(or equivalent) includes the @theme
directive with the required breakpoints. Here’s an example from the Nuxt UI documentation:
Make sure that --breakpoint-md
is defined. If you’re using Nuxt UI or Nuxt UI Pro, these are usually set up for you, but if you’ve customized your theme, you might have omitted them. Add or verify the breakpoints in your @theme
block to resolve the error.
Reference:See the section on customizing breakpoints and the CSS-first configuration approach in the Nuxt UI theming guide: Theme customization with @theme. If you’re using a custom setup or have removed the default breakpoints, re-add them as shown above. This should restore the
md
variant and resolve the error.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@1121449150140141648> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Yes, I have the theme layers, generally everything that is in the Tailwind documentation.
if you're using tailwind v4, it's probably because you haven't used an
@reference
in your style tagYeah, im searching a way to do it without the reference tag, because its really annoying to reference a file in EVERY style tag in the project
making classes like that kind of goes against the principles of tailwind, as far as i know there's no alternative except for downgrading to v3
if you want to reuse the same styles in many places it's generally better to make a component, otherwise just use it inline
Alright, thank you!
np!