img

FilterElements

HTML: <img>
XHTML: <img/>  or  <img />

Places an image on the page. The src and alt attributes are required. Many attributes of the img element have been deprecated in favor of Cascading Style Sheets for presentation and positioning.

Start/End Tags

This is an empty element. In HTML, the end tag is forbidden. In XHTML, the element must be closed with a trailing slash as just shown. Developers may include a space character before the slash for backward compatibility with older browsers.

Specifications

  • HTML 4.01
  • HTML5

align=

Values: bottom | left | middle | right | top
Deprecated. Not in HTML5. Specifies the alignment of an image using one of the following values:
bottom
Aligns the bottom of the image with the text baseline. This is the default vertical alignment.
left
Aligns the image on the left margin and allows subsequent text to wrap around it.
middle
Aligns the text baseline with the middle of the image.
right
Aligns the image on the right margin and allows subsequent text to wrap around it.
top
Aligns the top of the image with the top of the tallest object on that line.

alt=

Values: text
Required. Provides a string of alternative text that appears when the image is not displayed. Browsers may display this text as a “tool tip” when the mouse rests on the image.

border=

Values: number
Deprecated. Not in HTML5. Specifies the width (in pixels) of the border that surrounds a linked image.

height=

Values: number
Specifies the height of the image in pixels. It is not required but is recommended to speed up the rendering of the web page.

hspace=

Values: number
Deprecated. Not in HTML5. Specifies (in number of pixels) the amount of space to leave clear to the left and right of the image.

ismap

Values: None in HTML. (ismap="ismap" in XHTML)
Indicates that the graphic is used as the basis for a server-side image map (an image containing multiple hypertext links).

longdesc=

Values: URL
Not in HTML5. Specifies a link to a long description of the image or an image map’s contents. This may be used to make information about the image accessible to nonvisual browsers. It is not well supported.

name=

Values: text
Deprecated in XHTML 1.0. Not in HTML5.. Use id instead. Assigns the image element a name so that it can be referred to by a script or style sheet.

src=

Values: URL
Required. Provides the location of the graphic file to be displayed.

usemap=

Values: URL
Specifies the map containing coordinates and links for a client-side image map (an image containing multiple hypertext links).

vspace=

Values: number
Deprecated. Not in HTML5. Specifies (in number of pixels) the amount of space to leave clear above and below the image.

width=

Values: number
Specifies the width of the image in pixels. It is not required but is recommended to speed up the rendering of the web page.
HTML
<p>Your ideal pet: <img src="pig.png" alt="A pig"></p>
XHTML
<p>Your ideal pet: <img src="pig.png" alt="A pig" /></p>

Rendered Example

Your ideal pet: A pig

Photo by Keith Weller