I use CSS variables for color values all the time, and I often want to replicate them in JavaScript for charts and other graphics. Instead of copying the colors, I use this function:
function getCssVar (varName) {
return getComputedStyle(document.body)
.getPropertyValue(`--${varName}`)
}
Top comments (0)