HTML <img> Tag

Topic: HTML5 Tags ReferencePrev|Next


The <img> (short for image) tag defines an image in an HTML document. Images are not directly inserted into the document; they are linked to the HTML pages. The <img> element creates a holding space to embed the referenced image designated by the src attribute.

The following table summarizes the usages context and the version history of this tag.

Placement: Inline
Content: None. It is an empty element.
Start/End Tag: Start tag: required, End tag: forbidden
Version: HTML 2, 3.2, 4, 4.01, 5

Note: The browser may replace the image with the alternative text defined in this element's alt attribute in the case of non-graphical browsers, or if the browser is unable to display the image because it is invalid or an unsupported type.


The basic syntax of the <img> tag is given with:

HTML:<img src="URL" alt="text">; XHTML:<img src="URL" alt="text" />

The example below shows the <img> tag in action.

<img src="kites.jpg" alt="Flying Kites">
<img src="sky.jpg" alt="Cloudy Sky">
<img src="ballons.jpg" alt="Hot Air Ballons">

Tag-Specific Attributes

The following table shows the attributes that are specific to the <img> tag.

Attribute Value Description
Required — The following attributes must be specified on this tag for the markup to be valid.
alt text Provides an alternate text for an image.
src URL Specifies the URL of the image file to be displayed.
Optional — The following attributes are optional.
align left
Obsolete Specifies the alignment of an image with respect to the surrounding elements.
border pixels Obsolete Specifies the width of the border around the image.
crossorigin anonymous
Specifies how the element handles cross-origin requests.
height length Specifies the height of the image.
hspace pixels Obsolete Specifies the amount of whitespace on left and right side of an image.
ismap ismap This Boolean attribute defines that the image is part of a server-side map.
longdesc URL Obsolete Specifies a link to a long description of the image.
usemap URL Obsolete Defines a client-side image map associated with the img element.
vspace pixels Obsolete Specifies the amount of whitespace on top and bottom side of the image.
width length Specifies the width of the image.

Global Attributes

Like all other HTML tags, the <img> tag supports the global attributes in HTML5.

Event Attributes

The <img> tag also supports the event attributes in HTML5.

Browser Compatibility

The <img> tag is supported in all major modern browsers.

Browsers Icon

Basic Support—

  • Firefox 1+
  • Google Chrome 1+
  • Internet Explorer 2+
  • Apple Safari 1+
  • Opera 2.1+

Further Reading

See tutorial on: HTML Images.

Related tag: <figure>, <figcaption>.

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties