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

naturalHeight property (img)

Browser support:
9
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.

Syntax:

object.naturalHeight;
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:
<head>
    <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!");
            }
        }
    </script>
</head>
<body>
    <img id="image" src="bg.gif" width="60px" height="60px" />
    <button onclick="GetOrigSize ();">Get the original size of the image</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

User Contributed Comments

Post Content

Post Content