HTML | DOM image naturalWidth property
naturalWidth : property is used to get the original width of an image. Since the width of an image to be displayed on the webpage can be modified using the ‘width’ attribute of the <img> tag, hence the naturalWidth property becomes useful in situations where original width of the image is required rather than the customized one. It is a read-only property.
Syntax :
imageObject.naturalWidth
Return Value: It returns the original width of image in pixels.
Example:
<html> <body> <img src= id="image" alt="" width="250" height="205" class="alignnone size-medium wp-image-1092360" /> <br> <br> <button type="button" onclick="getWidth()">Click</button> <div id="text"></div> <script> function getWidth() { var imgObject = document.getElementById("image"); var output = document.getElementById("text"); output.innerHTML = "Width of image: " + imgObject.width + "<br>naturalWidth of image: " + imgObject.naturalWidth; } </script> </body> </html> |
Output:
Before click:

After click:

-
Supported browsers:
- Google Chrome
- Internet Explorer 9.0 or above
- Mozila Firefox
- Safari
- Opera
Recommended Posts:
- HTML | DOM Image name Property
- HTML | DOM Input Image alt Property
- HTML | DOM Input Image value Property
- HTML | DOM image naturalHeight property
- HTML | DOM Input Image name Property
- HTML | DOM Image complete Property
- HTML | DOM Input Image src Property
- HTML | DOM Input Image width Property
- HTML | DOM Input Image formEnctype Property
- HTML | DOM input image height Property
- HTML | DOM Input Image type Property
- HTML | DOM Input Image formNoValidate Property
- HTML | DOM Input Image form Property
- HTML | DOM Input image autofocus Property
- HTML | DOM Input Image disabled Property
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.



