Tailwindcss in Nuxt 4: Classes not working in global vue component
I am encountering a problem with rendering tailwindcss in my global vue component, but tailwind works fine in the pages dir.
I am parsing markdown using @nuxt/content through a global component called
OpinionSection.global.vue
I have this code currently:
My main.css:
My app.vue:
My opinion.vue page:
Here's also my nuxt.config.ts:
Thanks in advance for the help!12 Replies
Hi @MartinEnjoy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Your issue—Tailwind CSS classes not applying in your global Vue component (OpinionSection.global.vue), while working in pages—can be related to how Tailwind scans for class usage and how Nuxt handles global components.
Key points to check and solutions:
1. Tailwind Content Scanning
You are already using the
See: Nuxt UI Theme Customization 2. Global Components and Tailwind Nuxt auto-imports components in the
See: Nuxt Components Directory. 3. Slot Usage In your
See: Stack Overflow - Encapsulating css class doesn't apply [nuxt3] 4. Rebuild and Cache After changing Tailwind config or
@source directive in your main.css to explicitly include your components, content, and pages directories:
This is the correct approach for Tailwind CSS v4 and Nuxt UI, ensuring Tailwind picks up classes used in those files, including global components and markdown content. Make sure the relative paths in @source are correct based on the location of your main.css file. If main.css is in app/assets/css/, then ../../components/**/* should resolve to your components directory. Double-check the path if you moved files or directories recently.See: Nuxt UI Theme Customization 2. Global Components and Tailwind Nuxt auto-imports components in the
components/ directory, and you can make a component global by using the .global.vue suffix or placing it in a global/ subdirectory. This makes the component available everywhere, but it does not affect Tailwind's ability to scan for classes as long as your @source directives are correctSee: Nuxt Components Directory. 3. Slot Usage In your
OpinionSection.global.vue, you are passing classes to the <slot> element, but slots do not accept class attributes directly. The class should be applied to the parent element, not the slot. For example:
Do not write <slot class="...">, as this will not apply the class to the slotted content.See: Stack Overflow - Encapsulating css class doesn't apply [nuxt3] 4. Rebuild and Cache After changing Tailwind config or
@source directives, always restart your dev server to ensure Tailwind picks up new files and classes.
---
Summary of what to check:
- Ensure your @source paths in main.css are correct.
- Do not use class on <slot> elements; apply classes to the parent or wrapper elements.
- Restart your dev server after changes.
If you follow these steps and Tailwind classes are still not applied in your global component, double-check the file paths and ensure there are no typos or misconfigurations in your directory structure or Nuxt config.
If you need to see a working example of slot/class usage, refer to this Stack Overflow answer.
Let me know if you need further clarification!
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@475520454514180098> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
what are you using
@source for?It's for explicitly scanning for the .vue files in the path I set the
@source at I think.tried without?
Although I guess tailwind already scans it automatically.
Let me try removing
LOL after removing the @source, the markdown I am trying to render just disappeared
:pepo_think:
Weird one indeed
Might help with the context cause I get this warning when rendering the Opinion page with the global component:

I think
ContentRenderer from @nuxt/content just doesn't render tailwind classes I put in the global vue component hmmm, hella weird.well isn't the correct name for the component
ContentOpinionSection?
since it's in /components/content?Oh, wait....
I'll try that.
Both have it as ContentOpinionSection.global.vue, and have the parsed named slot as