The Image() constructor creates a new HTMLImageElement instance. It is functionally equivalent to document.createElement('img').
Disambiguation: image(), the CSS function notation.
Syntax
var htmlImageElement = new Image(width, height);
Parameters
width- The width of the image (i.e., the value for the
widthattribute). height- The height of the image (i.e., the value for the
heightattribute).
Usage 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 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.
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 StandardThe definition of 'Image()' in that specification. | Living Standard |
Browser compatibility
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
Image() constructor
|
Chrome
Full support 1 |
Edge
Full support 12 |
Firefox
Full support 1 |
IE
Full support 8 |
Opera
Full support 8 |
Safari
Full support 10.1 |
WebView Android
Full support 1 |
Chrome Android
Full support 18 |
Firefox Android
Full support 4 |
Opera Android
? |
Safari iOS
Full support 1 |
Samsung Internet Android
Full support 1.0 |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
Image() by Mozilla Contributors is licensed under CC-BY-SA 2.5.