Open In App

HTML DOM Screen Object

The Screen Object in HTML DOM is used to retrieve the information about the visitor; s or client screen. such as height and width of the screen and color resolution of the client screen. 

Note:  There is no public standard that applies to the screen object. 



The Screen Object has some Properties:

Example: Below HTML code returns the height and width of the visitor’s screen. 






<!DOCTYPE html>
<html>
  
<head>
    <title>
        Returning the Screen height 
        and width Property in HTML
    </title>
  
    <style>
        h1 {
            color: green;
        }
  
        h2 {
            font-family: Impact;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h2>
        Returning the Screen height and 
        width Property in HTML
    </h2>
      
    <p>
        For checking the screen's total height,
        double click the "Check Height" button:
    </p>
  
    <br>
    <p>
        For checking the screen's total width,
        double click the "Check width" button:
    </p>
  
    <button ondblclick="check_height()">
        Check Height
    </button>
  
    <button ondblclick="check_width()">
        Check width
    </button>
      
    <p id="height"></p>
  
    <script>
        function check_height() {
            var h = "Total Screen Height In Pixels : "
                + screen.height;
  
            document.getElementById("height").innerHTML = h;
        }
  
        function check_width() {
            var w = "Total Screen width In Pixels : "
                + screen.width;
                  
            document.getElementById("height").innerHTML = w;
        }
    </script>
</body>
  
</html>

Output:

Example 2: Below HTML CODE returns the pixelDepth property. 




<!DOCTYPE html>
<html>
  
<head>
    <title>
        HTML DOM Screen Object
    </title>
      
    <style>
        h1 {
            color: green;
        }
  
        h2 {
            font-family: Impact;
        }
  
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
  
    <h2>HTML DOM Screen Object</h2>
      
    <p>
        For checking the screen's pixel depth,
        click the "submit" button:
    </p>
  
    <button onclick="check_pixel_depth()">
        Submit
    </button>
  
    <p id="geeks"></p>
  
    <script>
        function check_pixel_depth() {
            var r = "Pixel depth in bits per pixel : "
                + screen.pixelDepth;
                  
            document.getElementById("geeks").innerHTML = r;
        }
    </script>
</body>
  
</html>

Output:

Supported Browsers:


Article Tags :