Image naturalWidth Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Image


The naturalWidth property returns the original width of an image.

This property is read-only.

Return Value

A Number, representing the original width of an image in pixels

The following code shows how to return the original width of an image:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<img id="myImg" src="" style="width:500px;height:98px;">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {/*from ww  w  .j  a  v a  2  s . c o  m*/
    var x = document.getElementById("myImg").naturalWidth;
    document.getElementById("demo").innerHTML = x;


Related Tutorials