Get computed css styles for a given element

Blog / CSS3 ·

I just found out that it is possible with pure javascript. It's supported in all the major browsers. Find more information here.

getComputedStyle(document.querySelector("h1"), null);

Getting the background style for example:

getComputedStyle(document.querySelector("h1"), null).background;


Krasimir Tsonev With over two decades of deep programming expertise, I offer comprehensive web consultancy and stack audits, alongside specialized workshops, training, and engaging public speaking to elevate your team's skills and optimize your digital presence. Contact me.

Keywords: queryselector h1 null document queryselector h1 getcomputedstyle document queryselector
Share the post on Twitter, Facebook, LinkedIn