This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Image() constructor creates a new HTMLImageElement instance. It is functionally equivalent to document.createElement('img').
Note: This function should not be confused with the CSS image() function.
new Image() new Image(width) new Image(width, height)
width OptionalThe width of the image (i.e., the value for the width attribute).
height OptionalThe height of the image (i.e., the value for the height attribute).
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 are 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.
const 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" />
| Specification |
|---|
| HTML> # dom-image-dev> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
Image |
1 | 12 | 1 | 8 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 | 1 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image