Get CSS property value via JavaScript
17 March 2026 (Updated 17 March 2026)
Assuming you want to get the value of a variable named primary, you can do this:
window.getComputedStyle(document.body).getPropertyValue('--primary')
It’ll return an empty string if the variable doesn’t exist.
Tagged:
JavaScript recipes