CSS Variables defined in addBase not recognized when used in addComponents
#19418
-
DescriptionI'm using CSS variables to implement dynamic theming in Tailwind, where the actual color values change based on a Minimal Reproducible Configconst plugin = require('tailwindcss/plugin');
const dynamicThemeColors = {
'color-surface-primary': 'var(--color-surface-primary)',
'color-surface-secondary': 'var(--color-surface-secondary)',
'color-text-primary': 'var(--color-text-primary)'
};
module.exports = {
content: ['./src/**/*.{vue,js,ts,jsx,tsx}'],
theme: {
extend: {
colors: {
...dynamicThemeColors,
blue: {
500: '#3B82F6',
900: '#1E3A8A'
},
gray: {
50: '#F9FAFB',
900: '#111827'
}
}
}
},
plugins: [
plugin(({ addBase, addComponents, theme }) => {
addBase({
'[theme=light]': {
'--color-surface-primary': theme('colors.gray[50]'),
'--color-surface-secondary': theme('colors.blue[500]'),
'--color-text-primary': theme('colors.gray[900]')
},
'[theme=dark]': {
'--color-surface-primary': theme('colors.gray[900]'),
'--color-surface-secondary': theme('colors.blue[900]'),
'--color-text-primary': theme('colors.gray[50]')
}
});
addComponents({
'.custom_scrollbar': {
'&::-webkit-scrollbar': {
width: '12px'
},
'&::-webkit-scrollbar-thumb': {
background: 'var(--color-surface-primary)',
borderRadius: '100px'
}
}
});
})
]
};Expected BehaviorThe Actual BehaviorThe CSS variable appears not to be recognized or applied correctly when used directly in Questions
Environment
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Does it work as expected? https://play.tailwindcss.com/hfiPY1WKwR Can you provide a reproduction showing your non-working example? |
Beta Was this translation helpful? Give feedback.

Does it work as expected? https://play.tailwindcss.com/hfiPY1WKwR
Can you provide a reproduction showing your non-working example?