HTML
tag
Example
How to insert an image:
<img src="smiley-2.gif" alt=">Smiley face
"
width
=
"
42
"
height
=
"
42
"
Try it »
(More examples are at the bottom of the page)
Browser support





All major browsers support tag.
Tag Definition and Usage Notes
The tag defines an image in an HTML page.
The tag has two required attributes: src and alt.
**Note:** Technically, an image is not inserted into an HTML page; it is linked to the HTML page. The tag's role is to create a placeholder for the referenced image.
**Tip:** By nesting the tag inside the tag, you can add a link from the image to another document.
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 are deprecated: align, border, hspace, vspace.
Differences between HTML and XHTML
In HTML, the tag has no end tag.
In XHTML, The tag must be closed properly.
property
New : New attributes in HTML5.
| property | Value | Description |
|---|---|---|
| align | top |
bottom
middle
left
right | HTML5 does not support。HTML 4.01 已废弃。 Specifies如何根据周围的文本来排列图像。 |
| loading | eager: load immediately
lazy: load lazily | Specifies whether the browser should load the image immediately or delay loading it. | | alt | text | Specifies the alternative 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 image's cross-origin attribute | | height | pixels | Specifies the height of the image. | | hspace | pixels | Not supported in HTML5. Deprecated in HTML 4.01. Specifies the whitespace to the left and right 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 the URL of a document containing a long image description. | | 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 above and below the image. | | width | pixels | Specifies the width of the image. |
Global Attributes
The tag supports HTML Global Attributes.
Event attribute
The tag supports HTML Event Attributes.
Try it - Example
Insert images from different locations
This example demonstrates how to display images from other folders or servers on a web page.
Create an image link
This example demonstrates how to use an image as a link.
Create an image map
This example demonstrates how to create an image map with clickable areas. Each area is a hyperlink.
Related Articles
HTML Tutorial:HTML image
HTML DOM Reference Manual: Image Object