Support for Multiple Themes with Dark & Light Modes in Tailwind CSS v4 #17405
Replies: 1 comment 1 reply
-
You don't want to duplicate imports: @import "tailwindcss";
-@import "tailwindcss/utilities"; It seems you'd want your -:root {
+@theme {
--background: #ffffff;
--foreground: #171717; Consider renaming @theme {
- --background: #ffffff;
- --foreground: #171717;
+ --color-background: #ffffff;
+ --color-foreground: #171717; Change the @media (prefers-color-scheme: dark) {
:root {
- --background: #29292B;
- --foreground: #C9C7BA;
+ --color-background: #29292B;
+ --color-foreground: #C9C7BA;
}
} Be sure to put the aforementioned rule in +@layer theme {
@media (prefers-color-scheme: dark) {
:root {
--color-background: #29292B;
--color-foreground: #C9C7BA;
}
}
+} The other colors can go in your @theme {
…
+ --color-deep-aqua: #278783;
+ --color-peach-cream: #FFEBD0;
+ --color-peach-puff: #FEF1E1;
+ --color-fiery-red: #FC350B;
+ --color-soft-mint: #D1E0D7;
+ --color-steel-blue: #607EBC;
+ --color-soft-ivory: #ECE5D8;
+ --color-dark-cocoa: #321B1F;
+ --color-bright-orange-red: #F66435;
+ --color-light-cream: #F4EFCA;
} If you switch themes depending on the @layer theme {
[data-theme="jetBlack"] {
--color-background: …;
--color-foreground: …;
}
[data-theme="aquaPeach"] {
--color-background: …;
--color-foreground: …;
}
…
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I’m trying to implement multiple themes along with their respective dark and light modes using Tailwind CSS v4. can anyone help me how to achieve this effectively.
Beta Was this translation helpful? Give feedback.
All reactions