You are here: Reference > JavaScript > client-side > HTML DOM > properties > naturalHeight (img)

naturalHeight property (img)

Browser support:
Retrieves the original height of the linked image.
To get the original width of the linked image, use the naturalWidth property.
If you need the displayed size of an image, use the offsetWidth and offsetHeight properties.


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Integer that retrieves the height, in pixels.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the naturalHeight property:
    <script type="text/javascript">
        function GetOrigSize () {
            var image = document.getElementById ("image");
            if ('naturalHeight' in image) {
                var message = "The original size of the image:";
                message += "\n height: " + image.naturalHeight + "px";
                message += "\n width: " + image.naturalWidth + "px";
                alert (message);
            else {
                alert ("Your browser doesn't support this example!");
    <img id="image" src="bg.gif" width="60px" height="60px" />
    <button onclick="GetOrigSize ();">Get the original size of the image</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

User Contributed Comments

Post Content

Post Content