Tailwind 4 theme values are CSS custom properties that JavaScript can read
April 19, 2025
Tailwind 4 exposes all theme values as CSS custom properties, so JavaScript can just read them with getComputedStyle. You don’t need to import the config:
const styles = getComputedStyle(document.documentElement)
const primary = styles.getPropertyValue("--color-primary")
I used this for the topbar loading indicator. It gets my theme’s primary color instead of a hardcoded value, so it stays in sync with the theme:
topbar.config({ barColors: { 0: styles.getPropertyValue("--color-primary") } })