You can set CSS variables with JavaScript

2018-11-15

JavaScript:

DOMElement.style.setProperty('--primary-color', 'yellow')

CSS:

.my-element {
  background-color: var(--primary-color);
}

An article with more information:

https://medium.com/@_bengarrison/accessing-and-modifying-css-variables-with-javascript-2ccb735bbff0