How to get the height of device screen in JavaScript ?

Given an HTML document which is running on a device. The task is to find the height of the working screen device using JavaScript.
Prerequisite – How to get the width of device screen in JavaScript ?

Example 1: This example uses window.innerHeight property to get the height of the device screen. The innerHeight property is used to return the height of the device.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        How to get the device screen Height in JavaScript ?
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">  
            GeeksForGeeks 
        </h1>
  
    <p id="GFG_UP" 
       style="font-size: 19px;
              font-weight: bold;">
    </p>
  
    <button onclick="GFG_Fun()">
        click here
    </button>
  
    <p id="GFG_DOWN" 
       style="color: green;
              font-size: 24px;
              font-weight: bold;">
    </p>
  
    <!-- Script to display the device screen Height -->
    <script>
        var el_up = document.getElementById("GFG_UP");
        var el_down = document.getElementById("GFG_DOWN");
  
        el_up.innerHTML = 
          "Click on the button to get the" + 
          " Height of the device's screen";
  
        function GFG_Fun() {
            var Height = window.innerHeight;
            el_down.innerHTML = Height + " pixels";
        }
    </script>
</body>
  
</html>

chevron_right


Output:
Before clicking on the button:

After clicking on the button:



Example 2: This example uses document.documentElement.clientHeight method to get the Height of device screen.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE HTML>
<html>
  
<head>
    <title>
        How to get the device screen Height in JavaScript ?
    </title>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color:green;">  
            GeeksForGeeks 
        </h1>
  
    <p id="GFG_UP"
       style="font-size: 19px;
              font-weight: bold;">
    </p>
  
    <button onclick="GFG_Fun()">
        click here
    </button>
  
    <p id="GFG_DOWN" 
       style="color: green;
              font-size: 24px; 
              font-weight: bold;">
    </p>
  
    <!-- Script to display the device screen Height -->
    <script>
        var el_up = document.getElementById("GFG_UP");
        var el_down = document.getElementById("GFG_DOWN");
  
        el_up.innerHTML =
          "Click on the button to get the" +
          " Height of the device's screen";
  
        function GFG_Fun() {
            el_down.innerHTML =
                document.documentElement.clientHeight + " pixels";
        }
    </script>
</body>
  
</html>

chevron_right


Output:
Before clicking on the button:

After clicking on the button:

full-stack-img




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.