How to change CSS :root color variables in JavaScript?

Spread the love

To change CSS :root color variables in JavaScript, we call the setProperty method.

For instance, we write

document.documentElement.style.setProperty("--your-variable", "#FFF");

to call setProperty to define the --your-variable variable and set it to '#FFF'.

Leave a Reply

Your email address will not be published. Required fields are marked *