Back to feed
Dev.to
Dev.to
5/11/2026
Inline style attributes vs CSS variables: a Tailwind v4 light-mode debug story

Inline style attributes vs CSS variables: a Tailwind v4 light-mode debug story

Short summary

React inline styles defeat external CSS rules even with !important, blocking theme switching. Solution: set CSS custom properties in React instead of paint values, letting stylesheets control rendering. This enables robust light/dark mode switching without threading state through components.

  • Inline style attributes have higher CSS specificity than external rules including !important
  • Moving paint properties (background, color) to CSS variables delegates control to stylesheets
  • Pattern enables efficient theme switching and reduces React state complexity

Generated with AI, which can make mistakes.

Is this a good recommendation for you?

Explore more