Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you inspect CSS variables in the browser?

I am defining my variables as per the spec like so:

:root {  --my-colour: #000; } 

And accessing them like this:

.my-element {   background: var( --my-colour ); } 

Which works fine.

However I was wondering if there was a way of debugging or inspecting the :root CSS rule to see what variables have been defined, and what their values were?

From my understanding the :root selector and html selectors both target the same element however when I inspect the html element using Chrome's debugging tools I cannot see anything defined:

inspecting the html element

Is there a way finding out what variables have been defined and their values?

like image 881
Paul. B Avatar asked Feb 24 '16 14:02

Paul. B


People also ask

Can you see CSS in inspect?

# View an element's CSSRight-click the Inspect me! text below and select Inspect. The Elements panel of DevTools opens. Inspect me!

How do you find the CSS of an element from inspect?

First, hover over the element you want to copy. Then, right-click on it and choose the option “Inspect”. On the left side is the HTML DOM tree, and on the right side, the CSS styles of the selected element.

How do I inspect element in my browser?

One of the easiest ways to inspect a specific web element in Chrome is to simply right-click on that particular element and select the Inspect option. Clicking on the Inspect option from the right-click menu will directly open the Developer tools including the editor, Console, Sources, and other tools.


2 Answers

Using Chrome Canary, you can access this by viewing the element's Computed styles and enabling the Show all filter:

Computed tab ... Example

like image 102
James Donnelly Avatar answered Sep 24 '22 12:09

James Donnelly


Safari (43) - in the developer tools, there is a little icon you can click to reveal the value.

enter image description here

Firefox (58) - in the developer tools, the CSS vars have a dotted line, when you hover, the value get's displayed as a tooltip.

enter image description here

Chrome (67) - in the developer tools, the CSS var values are also displayed as a tooltip when hovering. When the value is a color, it will display the color in a box. (hard to take a screenshot, but it looks similar to Firefox)

like image 28
Frank Lämmer Avatar answered Sep 21 '22 12:09

Frank Lämmer