Skip to content
Nate
Stephens

Get and Set CSS Variable Values

I always forget how to do this and need to look it up.

Get

const primaryColorValue = getComputedStyle(
  document.documentElement
).getPropertyValue('--color-primary');

Set

document.documentElement.style.setProperty(
  '--color-primary',
  'hsl(230deg 100% 67%)'
);

Last Updated: