Saturday, October 18, 2025
HomeLanguagesJavascriptJavaScript Window getComputedStyle() Method

JavaScript Window getComputedStyle() Method

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. 

Syntax:

window.getComputedStyle(element, pseudoElement)

Parameters:

  • 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. 

html




<h1 id="test" style="color:green">
    neveropen
</h1>
<button onclick="myFunction()">
    Try it
</button>
<p>
    The computed font-family of text
    in the test div is:
    <span id="demo"></span>
</p>
  
<script>
    function myFunction() {
      
        var elem = document.getElementById("test");
        var theCSSprop =
            window.getComputedStyle(
                elem, null).getPropertyValue("font-family");
        document.getElementById("demo").innerHTML =
                        theCSSprop;
    }
</script>


Output: 

JavaScript Window getComputedStyle() Method

JavaScript Window getComputedStyle() Method

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

  • Google Chrome 1.0
  • Edge 12.0
  • Internet Explorer 9.0
  • Firefox 1.0
  • Opera 7.2
  • Safari 3

We have a complete list of HTML and Window methods, to check those please refer to this HTML DOM Complete Reference article

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS