HTML <img>
Tag
Example
How to insert an image:
<img decoding="async" src="smiley-2.gif" alt="Smiley face" width="42" height="42">
Browser Support
All major browsers support the <img>
tag.
Tag Definition and Usage
The <img>
tag defines an image in an HTML page.
The <img>
tag has two required attributes: src
and alt
.
Note: Technically, images are not inserted into an HTML page, but linked to the HTML page. The <img>
tag creates a placeholder for the referenced image.
Tip: To add a link to an image, nest the <img>
tag inside the <a>
tag.
Differences Between HTML 4.01 and HTML5
The following attributes are not supported in HTML5: align
, border
, hspace
, longdesc
, vspace
.
In HTML 4.01, the following attributes: align
, border
, hspace
, vspace
deprecated.
Differences Between HTML and XHTML
In HTML, the <img>
tag has no closing tag.
In XHTML, the <img>
tag must be properly closed.
Attributes
Attribute | Value | Description |
---|---|---|
align | top <br>bottom <br>middle <br>left <br>right | Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of the image according to the surrounding text. |
loading | eager: Load immediately <br>lazy: Defer loading | Specifies whether the browser should load the image immediately or defer loading. |
alt | text | Specifies an alternate text for the image. |
border | pixels | Not supported in HTML5. Deprecated in HTML 4.01. Specifies the border around the image. |
crossorigin New | anonymous <br>use-credentials | Sets the cross-origin attribute for the image. |
height | pixels | Specifies the height of the image. |
hspace | pixels | Not supported in HTML5. Deprecated in HTML 4.01. Specifies the white space to the left and right of the image. |
ismap | ismap | Specifies an image as a server-side image map. |
longdesc | URL | Not supported in HTML5. Deprecated in HTML 4.01. Points to a URL containing a long description of the image. |
src | URL | Specifies the URL of the image to be displayed. |
usemap | #mapname | Specifies an image as a client-side image map. |
vspace | pixels | Not supported in HTML5. Deprecated in HTML 4.01. Specifies the white space above and below the image. |
width | pixels | Specifies the width of the image. |
Global Attributes
The <img>
tag supports HTML global attributes.
Event Attributes
The <img>
tag supports HTML event attributes.
Try It Yourself - Examples
Inserting an image from a different location
Related Articles
HTML Tutorial: HTML Images
HTML DOM Reference: Image Object