HTML Dog
Skip to navigation

HTML Tag: img

Image. This could be a photograph or graph or any other meaningful pictorial content. It should not be used purely for presentation, where CSS, such as background-image is more appropriate.

img has no content and therefore does not warrant a closing tag.

Required Attributes

Attribute Description Possible values
src The location of the image file to be used. URL.

Optional Attributes

Attribute Description Possible values
alt Alternative text that will replace the image if the image isn’t available. This must be included, if possible. In circumstances where it isn’t, the img must be the only content of a figure element in addition to a figcaption that contains a caption for the image. Text.
width The width of the image in pixels. This can also be done, or overridden, with CSS. Number.
height The height of the image in pixels. This can also be done, or overridden, with CSS. Number.
ismap Indicates that the element is a used as a server-side image map. None.
usemap Image map name. Hash name (eg. #flyer) matching the name of a map element (eg. <map name="flyer">…).
crossorigin Used in conjunction with JavaScript to determine how Cross Origin Resource Sharing requests are handled.
  • anonymous
  • use-credentials
Global attributes

Example


<img src="http://www.htmldog.com/badge1.gif" alt="HTML Dog" width="120" height="90">