JavaScript

Using javascript to get/set CSS custom variables

How to get and set CSS variable property values.

To get a value use the .getPropertyValue() method

element.style.getPropertyValue("--var")

To set a value use the .setProperty() method.

element.style.setProperty("--var", "NEW_VALUE")

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow