Controlling CSS Variables from JavaScript



Did you know that it is possible to retrieve the value of CSS variables and update their values from inside your JavaScript code?

Code from video: https://gist.github.com/prof3ssorSt3v3/698f6e97ce5657e9738d9fa9248b5e52

11 thoughts on “Controlling CSS Variables from JavaScript

  1. Too complicated and cumbersome for me.
    I much rather prefer : element.style.propertyname = "value";
    for example: document.getElementById("name").style.backgroundColor = "rgba(255,255,255,1)"

  2. Steve, I have no doubt you're a very capable developer but why do you use let and const the way you do? Best practice is using const as your default and only using let when the variable needs to be reassigned. However it seems you declare everything with let except for arrow functions, which is odd.

Leave a Reply

Your email address will not be published.