v4 @theme vs. @theme inline #18560
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
TL;DR: With Related: So, Additionally, I would declare styles for different variants using I created a much smaller example than yours: Here you can see that both Note: You can also declare color values only for
@theme inline {
--text-color-primary: var(--color-slate-900);
--background-color-secondary: var(--color-slate-200);
}
/* Warning: Just an example - code does not work in practice! */
@layer theme {
* {
@variant dark {
--text-color-primary: var(--color-white);
--background-color-secondary: var(--color-zinc-700);
}
}
}The In that case, the system leaves the override up to you - so in this example, you'd have to manually override:
I'm guessing that's not what you want. To have TailwindCSS generate global variables for /* Without inline */
@theme {
--text-color-primary: var(--color-slate-900);
--background-color-secondary: var(--color-slate-200);
}
@layer theme {
* {
@variant dark {
/* a variable declared in @theme (without inline)
has a corresponding global variable, which can be overridden */
--text-color-primary: var(--color-white);
--background-color-secondary: var(--color-zinc-700);
}
}
}
Or, in the case of inline, you need to override your local colors manually in dark mode: @theme inline {
--text-color-primary: var(--color-slate-900);
--background-color-secondary: var(--color-slate-200);
}
@layer theme {
* {
@variant dark {
/* a color declared in @theme inline does not have a global variable,
so you need to override the assigned variable directly */
--color-slate-900: var(--color-white);
--color-slate-200: var(--color-zinc-700);
}
}
}
|
Beta Was this translation helpful? Give feedback.










TL;DR: With
@theme inline, you are responsible for providing the variable override, since the variable does not exist globally.In contrast, with
@theme, the value is embedded into a global variable, which means its value can be overridden later.Related:
@themevs@layer themevs:rootSo,
@themeand@theme inlinecan be used together - and in fact, you can declare them in multiple places.Additionally, I would declare styles for different variants using
@variant, either inside*,:root, or:host. You can read more about which one to use in this question:*and when should I use:root, :hostas the parent selector?I…