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.cssText = "--tab-count: 3";
2/or/
3document.documentElement.style.setProperty("--tab-count", 5);
4/or/
5document.documentElement.setAttribute("style", "--tab-count: 5");
1let root = document.documentElement;
2
3root.addEventListener("mousemove", e => {
4 root.style.setProperty('--mouse-x', e.clientX + "px");
5 root.style.setProperty('--mouse-y', e.clientY + "px");
6});