getComputedStyle(document.documentElement)
.getPropertyValue('--my-variable-name') // hsl(218, 52%, 23%)
You can use this easily in any JavaScript project. As an example, I’m using it with Svelte to switch my Plotly charts between light and dark mode.