Skip to content

Instantly share code, notes, and snippets.

@jportella93
Last active May 30, 2019 12:04
Show Gist options
  • Save jportella93/753886885bf6f14ff3959ed5530ab283 to your computer and use it in GitHub Desktop.
Save jportella93/753886885bf6f14ff3959ed5530ab283 to your computer and use it in GitHub Desktop.
Set CSS variables and access them with JavaScript.
const stringVariable = getComputedStyle(document.documentElement)
.getPropertyValue('--height'); // '60px'
const heightInPx = Number(stringVariable.match(/[0-9]*/)[0]); // 60
:root {
--height: 60px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment