Feature Request: Bring Back Dark-Mode-Specific CSS Variables in Tailwind 4 #16730
pcoterecollective
started this conversation in
Ideas
Replies: 3 comments 4 replies
-
You can sort of do this already using regular CSS with @import "tailwindcss";
@custom-variant dark (&:where(.dark, .dark *));
@theme inline {
--color-background: var(--color-white);
}
@layer theme {
* {
@variant dark {
--color-background: var(--color-black);
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
How did you do it in v3? It should be the same or simpler in v4. We don't have and never had a native way of doing it so whatever technique you used should be possible in v4 as well. |
Beta Was this translation helpful? Give feedback.
1 reply
-
You mean something like this? :root {
--gray-950:
--gray-50:
}
@theme {
--color-gray-950: var(--gray-950);
--color-gray-50: var(--gray-50);
}
@media (prefers-color-scheme: dark) {
@theme inline {
--background: var(--gray-950);
--foreground: var(--gray-50);
}
}
@media (prefers-color-scheme: light) {
@theme inline {
--background: var(--gray-50);
--foreground: var(--gray-950);
}
}
body {
color: var(--foreground);
background: var(--background);
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Description
In Tailwind CSS 3, defining dark-mode-specific CSS variables was straightforward, making it easy to customize themes without adding extra utility classes. However, in Tailwind CSS 4, there doesn’t seem to be a built-in way to achieve this efficiently. The current approach requires applying two separate classes (e.g.,
bg-slate-200 dark:bg-slate-900 text-slate-900 dark:text-slate-100
), which can be cumbersome when handling multiple dark-mode-specific styles.Request
Reintroduce a way to define dark-mode-specific CSS variables within Tailwind’s configuration or provide a recommended approach for theming that avoids excessive class duplication.
Maybe something like this
This would improve maintainability and keep styles more manageable, especially for complex themes.
Would love to see this feature reconsidered!
Beta Was this translation helpful? Give feedback.
All reactions