Nuxt UI 3 Dynamic Theming
Tello,
It's in the name :), I would like to do like Nuxt UI 3 page: Allow the user to choose the primary color (or more) to retheme dynamically.
I tried to research about it here and there, but I can't find more than chaning CSS variable, which would be a very tailwind way.
Is there a way to dynamically override UI 3 palette to have a more effective dynamic theming ?
Thanks 🙂

8 Replies
Hi @Omnislash. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Yes, you can implement dynamic theming in Nuxt UI 3 similar to how the Nuxt UI documentation site does it. There are two main approaches:
Using App Config (for Nuxt projects)
In Nuxt UI 3, you can dynamically change the primary color (and other colors) at runtime using the reactive app config:
This approach leverages Nuxt's App Config system, which is reactive. When you change
appConfig.ui.colors.primary
, all components using that color will update automatically.
Using CSS Variables (alternative approach)
For more fine-grained control, you can also use CSS variables to override specific color shades:
You can dynamically change these variables using JavaScript:
Implementation Example
The Nuxt UI documentation site itself uses this approach. According to a Stack Overflow post, they change the config reactively to implement their theme picker feature Stack Overflow Post.
You can set up your initial configuration in app.config.ts
:
Then modify it dynamically in your components as shown above.
For more detailed information on theming in Nuxt UI 3, check out the Nuxt UI Theme documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai very nice thanks, looks good, but what about fully custom colors instead of existing tailwind colors ? Can I add a new brand new palette in useAppConfig ?
Let me check the knowledge base for you again. One moment! :books:
----------------------
Yes, you can definitely add custom colors beyond the existing Tailwind colors in Nuxt UI 3. There are two approaches to implement fully custom color palettes:
1. Using CSS Variables with
@theme
directive
For fully custom colors, you can define your own color palette using CSS variables in your main CSS file:
2. Registering Custom Colors in App Config
To use your custom color in the app config system, you need to:
1. Define the color in your nuxt.config.ts
file:
2. Then you can use it in your app.config.ts
:
3. Now you can dynamically change it:
This approach allows you to define completely custom color palettes that aren't part of the default Tailwind colors, and still use them with all Nuxt UI components through the color="mybrand"
prop.
For more information on customizing the theme in Nuxt UI, check the Nuxt UI Theme documentation.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai in your exemple I still have to create "mybrand" in main.css first.
Is it possible to define a full new color in runtime ?
Let me check the knowledge base for you again. One moment! :books:
----------------------
You're right about the limitation in my previous example. Let's clarify how to define a completely new color palette at runtime in Nuxt UI 3.
For fully dynamic color creation at runtime (without predefined CSS variables), you have a couple of options:
Using v-bind in CSS
You can use Vue's
v-bind
in your CSS to dynamically bind JavaScript variables to CSS properties:
This approach uses Vue's dynamic styles with v-bind feature, allowing you to create and modify color palettes entirely at runtime.
Programmatically Setting CSS Variables
Alternatively, you can programmatically set CSS variables:
Remember that for either approach, you'll still need to register the color name in your Nuxt config to use it with component props like color="mybrand"
, but the actual color values can be completely dynamic.
These methods allow you to create entirely new color palettes at runtime without having to predefine them in your CSS files.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.