Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | Window getComputedStyle() Method

  • Last Updated : 26 Jul, 2019

The getComputedStyle() method is used to get all the computed CSS property and values of the specified element.
The use of computed style is displaying the element after stylings from multiple sources have been applied.
The getComputedStyle() method returns a CSSStyleDeclaration object.


window.getComputedStyle(element, pseudoElement)


  • element: The element to get the computed style for
  • pseudoElement: A pseudo-element to get. this is an optional parameter.

Example: Return font-family of text in div.

<!DOCTYPE html>
        HTML | DOM Window getComputedStyle() Method
        div {
            color: white;
            text-align: justify;
            <button onclick="myFunction()">
                Try it
        <div id="test" style="height: 100px; 
                    background-color: green; 
                    font-size: 50px;
                    padding-left: 140px;
                    padding-top: 50px;">
            Geeks for Geeks
          The computed font-family of text 
          in the test div is:
          <span id="demo"></span>
            function myFunction() {
                var elem = document.getElementById("test");
                var theCSSprop =
                        elem, null).getPropertyValue("font-family");
                document.getElementById("demo").innerHTML = 

Before click on button:

After click on button:

Supported Browsers: The browser supported by Window getComputedStyle() Method are listed below:

  • Google Chrome 11.0
  • Internet Explorer 9.0
  • Firefox 4.0
  • Opera 11.5
  • Safari 5

My Personal Notes arrow_drop_up
Recommended Articles
Page :