HTML <img>Tag
Examples
How to insert an image:
Try it Yourself »
(More examples at the bottom of the page)
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the <img> tag.
Tag Definition and Usage Instructions
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; they are linked to the HTML page. The <img> tag creates a placeholder for the referenced image.
Tip:By nesting the <img> tag inside an <a> tag, you can add a link to another document to the image.
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, vspaceare deprecated。
Differences between HTML and XHTML
In HTML, the <img> tag has no end tag.
In XHTML, the <img> tag must be properly closed.
Attributes
New: New attribute in HTML5.
| Attribute | Value | Description |
|---|---|---|
| align | top bottom middle left right |
Not supported in HTML5. Deprecated in HTML 4.01.Specifies how to align an image according to the surrounding text. |
| loading | eager: Load immediately lazy: Lazy loading |
Specifies whether the browser should load the image immediately or defer loading it. |
| alt | text | Specifies alternate text for the image. |
| border | pixels | Not supported in HTML5. Deprecated in HTML 4.01.Specifies the border around the image. |
| crossoriginNew | anonymous use-credentials |
Sets the cross-origin attribute of the image. |
| height | pixels | Specifies the height of the image. |
| hspace | pixels | Not supported in HTML5. Deprecated in HTML 4.01.Specifies the whitespace on the left and right sides of the image. |
| ismap | ismap | Specifies the image as a server-side image map. |
| longdesc | URL | Not supported in HTML5. Deprecated in HTML 4.01.Points to a URL of a document containing a long description of the image. |
| src | URL | Specifies the URL of the image to display. |
| usemap | #mapname | Defines the image as a client-side image map. |
| vspace | pixels | Not supported in HTML5. Deprecated in HTML 4.01.Specifies the whitespace at the top and bottom of the image. |
| width | pixels | Specifies the width of the image. |
Global Attributes
The <img> tag supportsHTML Global Attributes。
Event Attributes
The <img> tag supportsHTML Event Attributes。
Try it Yourself - Examples
Insert images from different locations
This example demonstrates how to display images from other folders or servers on a webpage.
Making an image link
This example demonstrates how to use an image as a link.
Creating an image map
This example demonstrates how to create an image map with clickable areas. Each area in it is a hyperlink.
Related Articles
HTML Tutorial:HTML Images
HTML DOM Reference:Image Object
Other extensions