HTML | DOM image naturalHeight property

naturalHeight : This property is used to get the original height of an image. Since the height of an image to be displayed on the webpage can be modified using the ‘height’ attribute in the <img> tag, hence the naturalHeight property becomes useful in situations where the original height of the image is required rather than the customized one and it is a read-only property.

Syntax :

imageObject.naturalHeight

Return Value: It returns the original height of an image in pixels.



Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

<html>
  
<body>
    <center>
        <img src=
             id="image" alt="" width="250" height="205" 
             class="alignnone size-medium wp-image-1092360" />
        <br>
        <br>
        <button type="button" onclick="getHeight()">Click</button>
        <div id="text"></div>
    </center>
    <script>
        function getHeight() {
            var imgObject = document.getElementById("image");
            var output = document.getElementById("text");
            output.innerHTML = "Height of image: " + imgObject.height +
                "<br>naturalHeight of image: " + imgObject.naturalHeight;
        }
    </script>
</body>
  
</html>

chevron_right


Output:
Before click:

After click:

    Supported browsers :

  • Google Chrome
  • Internet Explorer 9.0 or above
  • Mozila Firefox
  • Safari
  • Opera


My Personal Notes arrow_drop_up


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 :
Practice Tags :


Be the First to upvote.


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