The Image() constructor creates a new HTMLImageElement instance. It is functionally equivalent to document.createElement('img').

Syntax

var htmlImageElement = new Image(width, height);

Parameters

Note: The entire bitmap is loaded regardless of the sizes specified in the constructor. The size specified in the constructor is reflected through the properties HTMLImageElement.width and HTMLImageElement.height of the resulting instance. The intrinsic width and height of the image in CSS pixels is reflected through the properties HTMLImageElement.naturalWidth and HTMLImageElement.naturalHeight. If no size is specified in the constructor both pairs of properties have the same values.

width
The width of the image (i.e., the value for the width attribute).
height
The height of the image (i.e., the value for the height attribute).

Examples

var myImage = new Image(100, 200);
myImage.src = 'picture.jpg';
document.body.appendChild(myImage);
This would be the equivalent of defining the following HTML tag inside the <body>:
<img width="100" height="200" src="picture.jpg">

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'Image()' in that specification.
Living Standard  

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Image() constructorChrome Full support 31Edge Full support YesFirefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android ? Safari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown