var root = document.querySelector(':root');
root.style.setProperty('--variable', 'lightblue');
/or/
root.style.setProperty('--variable', myColor);
let docStyle = getComputedStyle(document.documentElement);
//get variable
let myVarVal docStyle.getPropertyValue('--my-variable-name');
//set variable
docStyle.setProperty('--my-variable-name', '#fff');
getComputedStyle(document.documentElement)
.getPropertyValue('--my-variable-name'); // #999999
document.documentElement.style.setProperty("--main-background-color", "green");
document.documentElement.style.cssText = "--tab-count: 3";
/or/
document.documentElement.style.setProperty("--tab-count", 5);
/or/
document.documentElement.setAttribute("style", "--tab-count: 5");
document.documentElement.setAttribute("style", "--main-background-color: green");
document.documentElement.style.setProperty("--main-background-color", "green");
const docStyles = document.documentElement.style;
docStyles.setProperty('--accent', '#ffffff');
docStyles.setProperty('--textColor', '#ffffff');
document.documentElement.style.cssText = "--main-background-color: red";