set css property to variable code example
Example 1: set css variable from javascript
document.documentElement.style.cssText = "--tab-count: 3";
/or/
document.documentElement.style.setProperty("--tab-count", 5);
/or/
document.documentElement.setAttribute("style", "--tab-count: 5");
Example 2: javascript use css custom properties
Values in JavaScript
To use the values of custom properties in JavaScript, it is just like standard properties.
element.style.getPropertyValue("--my-var");
getComputedStyle(element).getPropertyValue("--my-var");
element.style.setProperty("--my-var", jsVar + 4);