1var root = document.querySelector(':root');
2root.style.setProperty('--variable', 'lightblue');
3/or/
4root.style.setProperty('--variable', myColor);
1let docStyle = getComputedStyle(document.documentElement);
2
3//get variable
4let myVarVal docStyle.getPropertyValue('--my-variable-name');
5
6//set variable
7docStyle.setProperty('--my-variable-name', '#fff');
1document.documentElement.style.setProperty("--main-background-color", "green");
1document.documentElement.style.cssText = "--tab-count: 3";
2/or/
3document.documentElement.style.setProperty("--tab-count", 5);
4/or/
5document.documentElement.setAttribute("style", "--tab-count: 5");
1document.documentElement.setAttribute("style", "--main-background-color: green");