Access CSS variable from javascript [duplicate]

Just the standard way: Get the computed styles with getComputedStyle Use getPropertyValue to get the value of the desired property getComputedStyle(element).getPropertyValue(‘–color-font-general’); Example: var style = getComputedStyle(document.body) console.log( style.getPropertyValue(‘–bar’) ) // #336699 console.log( style.getPropertyValue(‘–baz’) ) // calc(2px*2) :root { –foo:#336699; –bar:var(–foo); –baz:calc(2px*2); }

How to create color shades using CSS variables similar to darken() of Sass?

The new Specification introduces “relative color syntax” where you can do the following :root { –color-primary: #f00; /* any format you want here */ –color-primary-darker: hsl(from var(–color-primary) h s calc(l – 5%)); –color-primary-darkest: hsl(from var(–color-primary) h s calc(l – 10%)); } The idea is to convert the main color to hsl format and using calc() … Read more

How do I debug CSS calc() value?

Is there a way to validate/highlight formulas errors? You need to check to see if you aren’t breaking any rules when defining your formula. Here it is from the specification: At each operator, the types of the left and right argument are checked for these restrictions. If compatible, the type resolves as described below (the … Read more