JavaScript | Window innerWidth and innerHeight Properties

The innerWidth property in JavaScript returns the width and innerHeight property returns the height of window content area.

Syntax:

window.innerWidth
window.innerHeight

Parameter: It doesn’t required any parameters.

Return Value: It Returns a number, Representing the Width and Height of the window’s content area.

Note: For IE 8 i.e (Internet Edg 8) or earlier, use clientWidth and clientHeight to get width and height of window.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
     <head>
          <title>Browser Inner width and height</title>
          <style>
            body{
                text-align:center;
            }
            .gfg {
                font-size:40px;
                font-weight:bold;
                color:green;
            }
          </style>
     </head>
     <body>
     <div class = "gfg">GeeksforGeeks</div>
     <h2>Browser Window</h2>
     <p id="demo"></p>
     <script>
          var Width, Height, result;
  
          // height and width of Browser window
          Width = window.innerWidth || document.documentElement.clientWidth
                  || document.body.clientWidth;
  
          Height = window.innerHeight || document.documentElement.clientHeight
                  || document.body.clientHeight;
          // Display Width and Height.
          result = document.getElementById("demo");
          result.innerHTML = "Browser inner width: " + Width +
                              "<br>Browser inner height: " + Height;
  
     </script>
</body>
</html>

chevron_right


Output:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.