Tag Description
The img tag is used to link an image to an HTML page. The tag creates a holding space for the referenced image.
This tag has the form:
<img
alt="text"
src="URL"
height="{ number | percentage }"
width= "{ number | percentage }"
/>
HTML5 and HTML4.01 Differences
The layout attributes: align, border, hspace, and vspace were deprecated in HTML4.01, and are not supported in HTML5.
Attributes
Attribute | Value | Description |
---|---|---|
align | top bottom middle left right |
Specifies the alignment of an image according to surrounding elements
HTML4:
![]()
HTML5:
![]() |
alt | text | (required) Specifies alternate text for the image |
border | pixels | Specifies the width of the border around an image
HTML4:
![]()
HTML5:
![]() |
crossoriginHTML5 | anonymous use-credentials |
Allow images from third-party sites that allow cross-origin access to be used with canvas |
height | pixels % |
Specifies the height of the image |
hspace | pixels | Specifies the whitespace on left and right side of an image
HTML4:
![]()
HTML5:
![]() |
ismap | ismap | Defines the image as a server-side image map |
longdesc | URL | Specifies the URL to a document that contains a long description of the image
HTML4:
![]()
HTML5:
![]() |
src | URL | (required) Specifies the URL of the image |
usemap | URL | Specifies an image as a client-side image-map |
vspace | pixels | Specifies the whitespace on top and bottom of an image
HTML4:
![]()
HTML5:
![]() |
width | pixels % | Specifies the width of the image |
Global Attributes
This tag also supports the HTML Global Attributes.
Event Attributes
This tag also supports the HTML Event Attributes.
Examples
The following example shows the basic use of this tag:
<img src="smiley.gif" alt="Smiley face" />
This produces the following result:

Browser Support
Chrome | Firefox | IE | Safari | Opera |
---|---|---|---|---|
Doctype Declaration Support
The following table lists the doctype declarations this element may appear in:
HTML4.01 / XHTML1.0 | XHTML 1.1 | HTML 5 | ||
---|---|---|---|---|
Traditional | Strict | Frameset | ||
Miscellaneous Information
Defined In: | HTML 2 |
---|---|
Empty Tag: | Yes |