Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Find Native Image Width and Height</title> <script> function imgSize(){ var myImg = document.querySelector("#sky"); var realWidth = myImg.naturalWidth; var realHeight = myImg.naturalHeight; alert("Original width=" + realWidth + ", " + "Original height=" + realHeight); } </script> </head> <body> <img src="/examples/images/sky.jpg" id="sky" width="250" alt="Cloudy Sky"> <p><button type="button" onclick="imgSize();">Get Original Image Size</button></p> </body> </html>