You can do this quite easily with something like:
document.documentElement.style.setProperty('--themeColor', 'red');
Update: Not sure if the only question is to change the color as I thought. Now I have added the getRandomColor() example. Just getting random things can be a big load of work depending on if you want to keep the last used color by the user or so ...
:root { --themeColor: orange; } a { color: var(--themeColor) } div { width: 100px; height: 100px; background-color: var(--themeColor); }
<a href="#">Hello world</a> <div>Test</div>
source share