Tailwind classes not applying while using Nuxt UI v3
I'm running into some strange behaviors with Nuxt, using NuxtUI v3.
I followed the installation guide on the Nuxt site (including wrapping <NuxtPage> in <UApp>). Using components like <UCard> works and displays, but trying to apply classes like
class="font-bold"
doesn't do anything. I also tried adding a font in my theme, but trying to apply those doesn't result in anything either.
I'm not sure what I'm doing wrong, haha6 Replies
Hi @Viridian. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I can see you're having issues with Tailwind CSS classes not applying in your Nuxt UI v3 project. Let's troubleshoot this issue based on the information provided.
The Problem
Your Tailwind classes like
font-bold
aren't applying, and your custom font defined in the @theme
directive isn't working either.
Possible Solutions
1. Check CSS Import Order
Make sure your CSS imports are in the correct order. The Nuxt UI documentation recommends:
Note that you're using --font-site
but Nuxt UI uses --font-sans
by default. Try changing this to match the expected variable name.
2. Ensure Proper CSS File Registration
Verify that your CSS file is properly registered in your nuxt.config.ts
. Your configuration looks correct, but double-check the path to make sure it's pointing to the right location:
3. Use the ui
Prop for Component Customization
For Nuxt UI v3, component customization works through the ui
prop and the Tailwind Variants API. For example:
This approach is different from v2, as mentioned in the migration guide.
4. Global Theme Configuration
You can also set global theme configurations in your app.config.ts
:
5. Font Registration
For custom fonts, make sure they're properly registered. Nuxt UI integrates with Nuxt Fonts automatically, so you can declare your font in CSS:
But you need to make sure the font is actually available. You might need to import it first:
As mentioned in a Stack Overflow solution, proper font registration is important.
Additional Recommendations
1. Make sure you've wrapped your app with the UApp
component as you mentioned:
2. Consider adding VSCode settings for better Tailwind CSS IntelliSense:
3. If you're using pnpm, ensure you've set shamefully-hoist=true
in your .npmrc
file or installed tailwindcss
in your project's root directory.
If these solutions don't resolve your issue, you might need to check for any conflicts between your modules or consider creating a minimal reproduction of the issue to share with the Nuxt community.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Solved because of some stupid scoped css issues 🤣
@kapa.ai I made an
app.config.ts
with this configuration:
But the theme colors aren't changing even after restarting the application. Why is this? I'm using @nuxt/uiLet me check the knowledge base for you again. One moment! :books:
----------------------
I can see you're having trouble with changing theme colors in Nuxt UI v3. Let's look at what might be happening.
Based on the knowledge sources, your configuration in
app.config.ts
looks correct for Nuxt UI v3. The colors should be defined under the ui.colors
object as you've done:
However, there are a few potential reasons why your theme colors aren't changing:
Possible Issues
1. Nuxt UI Version: Make sure you're using Nuxt UI v3. In v2, the configuration was different - colors were defined directly under the ui
key without the colors
object:
2. Hot Module Replacement: According to the Nuxt UI documentation, the color aliases can be configured at runtime, which means changes should apply without a full rebuild. However, sometimes a full restart is needed.
3. CSS Variables: Check if you're using the new CSS variable format in your components. In Nuxt UI v3, you should use design tokens like text-(--ui-primary)
instead of direct color references like text-primary
.
4. AppConfig Reactivity: The AppConfig is reactive, as mentioned in a Stack Overflow post, so changes should apply dynamically.
Solutions to Try
1. Clear Cache: Try clearing your browser cache and Nuxt's cache (.nuxt
directory).
2. Use Design Tokens: Make sure you're using the new design token format in your components:
3. Check Component Props: For components that accept a color
prop, make sure you're using the semantic color names:
4. Verify Theme Configuration: If you've added custom colors, ensure they're also defined in your nuxt.config.ts
under the ui.theme.colors
array.
If you're still experiencing issues after trying these solutions, it might be helpful to create a minimal reproduction of the problem to share with the Nuxt UI community for more specific assistance.
Nuxt UI Theme Documentation provides more details on theme customization in v3.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@173158033742888961> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Add shamefully hoist in .npmrc
And run pnpm install