Why using CSS variables, instead of inline styles? #93
-
Hi, I stumbled upon this project and I'm considering to use this for a project. I wanted to know if the authors of this project have considered using inline styles instead of CSS variables to implement the dynamic part? What argument was for using CSS variables instead of directly going to inline styles for dynamic values? Any known advantages/disadvantages (also in terms of performance) regarding using CSS variables vs of inline styles? Thanks! Vinh |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Using CSS variables allows you to use conditions that are not possible with inline styles. Conditions like media queries or pseudo selectors. Also if you combine the use of CSS and inline styles, the inline styles will always have a higher specificity than styles applied by classes, making the CSS not work. One optimization this library could make is to use inline styles if no conditions are configured. Would need to fully think through the ramifications of that, though. |
Beta Was this translation helpful? Give feedback.
Using CSS variables allows you to use conditions that are not possible with inline styles. Conditions like media queries or pseudo selectors. Also if you combine the use of CSS and inline styles, the inline styles will always have a higher specificity than styles applied by classes, making the CSS not work.
One optimization this library could make is to use inline styles if no conditions are configured. Would need to fully think through the ramifications of that, though.