Open In App

HTML DOM Image height Property

Last Updated : 05 Oct, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML DOM Image height Property is used to set or returns the value of the height attribute of the Image element. The height attribute is used to specify the height of the image in terms of pixels. 

Syntax:

It returns the image height Property.

imageObject.height

It sets the image height property.

imageObject.height = pixels

 

Property Values:

  • pixels: It specifies the height of the Image Element in terms of pixels

Return Value: It returns a string value that represents the height of the image in terms of pixels.

Example 1: This example illustrates how to return the image height property. 

HTML




<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1 style="color: green">
            GeeksforGeeks
        </h1>
          
        <h2>HTML DOM Image Height Property</h2>
          
        <img id="GFG" src=
            width="400" height="150" />
        <br>
  
        <button onclick="Geeks()">
            Click me!
        </button>
          
        <p id="sudo"></p>
  
    </center>
  
    <script>
        function Geeks() {
            var g = document.getElementById("GFG").height;
              
            document.getElementById("sudo")
                    .innerHTML = g + "px";
        }
    </script>
</body>
  
</html>


Output:

Example 2: Below code sets the image height property.

HTML




<!DOCTYPE html>
<html>
  
<body>
    <center>
        <h1 style="color: green">
            GeeksforGeeks
        </h1>
          
        <h2>HTML DOM Image Height Property</h2>
          
        <img id="GFG" src=
            width="400" height="150" />
        <br>
  
        <button onclick="Geeks()">
            Click me!
        </button>
          
        <p id="sudo"></p>
  
    </center>
  
    <script>
        function Geeks() {
            var g = document.getElementById(
                    "GFG").height = "75";
  
            document.getElementById("sudo")
                    .innerHTML = g + "px";
        }
    </script>
</body>
  
</html>


Output:

Supported Browsers:

  • Google Chrome
  • Firefox
  • Internet Explorer
  • Apple Safari
  • Opera


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads