HTML XHTML The Complete Reference
home » reference » appendix a » html element reference

<img> (Image)


This element indicates a media object to include in an HTML document. Usually, the object is a graphic image, but some implementations support movies and animations.

Standard Syntax


<img
align="bottom | left | middle | right | top" (transitional only)
alt="alternative text"
border="pixels" (transitional only)
class="class name(s)"
dir="ltr | rtl"
height="pixels"
hspace="pixels" (transitional only)
id="unique alphanumeric identifier"
ismap="ismap"
lang="language code"
longdesc="url of description file"
name="unique alphanumeric identifier"
src="url of image"
style="style information"
title="advisory text"
usemap="url of map file"
vspace="pixels" (transitional only)
width="pixels"
/ >

Attributes Defined by Internet Explorer


accesskey="key" (5.5)
align="absbottom | absmiddle | baseline | texttop" (4)
datafld="name of column supplying bound data" (4)
datasrc="id of data source object supplying data" (4)
dynsrc="url of movie" (4)
galleryimg="yes | no | true | false" (6)
hidefocus="true | false" (5.5)
language="javascript | jscript | vbs | vbscript" (4)
loop="infinite | number" (4)
lowsrc="url of low-resolution image" (4)
tabindex="number" (5.5)
unselectable="on | off" (5.5)

Standard Events


onclick, ondblclick, onkeydown, onkeypress, onkeyup, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup

Events Defined by Internet Explorer


onabort, onactivate, onafterupdate, onbeforeactivate, onbeforecopy, onbeforecut, onbeforedeactivate, onbeforeeditfocus, onbeforepaste, onblur, oncontextmenu, oncontrolselect, oncopy, oncut, ondeactivate, ondrag, ondragend, ondragenter, ondragleave, ondragover, ondragstart, ondrop, onerrorupdate, onfilterchange, onfocus, onfocusin, onfocusout, onhelp, onload, onlosecapture, onmouseenter, onmouseleave, onmousewheel, onmove, onmoveend, onmovestart, onpaste, onpropertychange, onreadystatechange, onresize, onresizeend, onresizestart, onselectstart, ontimeerror

Element Specific Attributes


align
This attribute controls the horizontal alignment of the image with respect to the page. The default value is left. Only the Netscape, Internet Explorer 4, and WebTV implementations support the absbottom, absmiddle, baseline, and texttop values.

alt
This attribute contains a string to display instead of the image for browsers that cannot display images.

border
This attribute indicates the width in pixels of the border surrounding the image.

datafld
This attribute specifies the column name from the data source object that supplies the bound data to set the src of the <img> element.

datasrc
This attribute indicates the id of the data source object that supplies the data that is bound to this <img> element.

dynsrc
In the Microsoft and WebTV implementations, this attribute indicates the URL of a movie file and is used instead of the src attribute.

galleryimg
This Microsoft attribute is used to control whether the gallery image menu should appear when the mouse pointer hovers over an image. The default value is true or yes. A value of no or false suppresses the menu. A meta tag like <meta http-equiv="imagetoolbar" content="no" /> can be used to suppress the image toolbar document wide.

height
This attribute indicates the height in pixels of the image.

hspace
This attribute indicates the horizontal space in pixels between the image and surrounding text.

ismap
This attribute indicates that the image is a server-side image map. User mouse actions over the image are sent to the server for processing.

longdesc
This attribute specifies a URL of a document which contains a long description of the image. This attribute is used as a complement to the alt attribute.

loop
In the Microsoft implementation, this attribute is used with the dynsrc attribute to cause a movie to loop. Its value is either a numeric loop count or the keyword infinite.

lowsrc
In the Netscape implementation, this attribute contains the URL of an image to be initially loaded. Typically, the lowsrc image is a low-resolution or black-and-white image that provides a quick preview of the image to follow. Once the primary image is loaded, it replaces the lowsrc image.

name
This common attribute is used to bind a name to the image. Older browsers understand the name field, and in conjunction with scripting languages it is possible to manipulate images by their defined names to create effects such as "rollover" buttons. The id attribute under HTML 4 specifies element identifiers; for backward compatibility, name can still be used.

src
This attribute indicates the URL of an image file to be displayed.

usemap
This attribute makes the image support client-side image mapping. Its argument is a URL specifying the map file, which associates image regions with hyperlinks.

vspace
This attribute indicates the vertical space in pixels between the image and surrounding text.

width
This attribute indicates the width in pixels of the image.

Examples


<img src="mikka.jpg" lowsrc="mikkabw.jpg" alt="Grand Prix Driver" height="320" width="150" />

<img src="hugeimagemap.gif" usemap="#mainmap" border="0" height="200" width="200" alt="Image Map Here" />

<a href="home.htm"><img src="homebutton.gif" width="50" height="20" alt="Link to Home Page" /></a>

Compatibility


HTML 2, 3.2, 4, 4.01, XHTML 1.0, 1.1, Basic
Internet Explorer 2, 3, 4, 5, 5.5, 6
Netscape 1, 1.1, 2, 3, 4, 4.5-4.8, 6,7
Opera

Notes


Typically, when you use the usemap attribute, the URL is a fragment, such as #map1, rather than a full URL. Some browsers do not support external client-side map files.

Under the strict HTML and XHTML definitions, the <img> tag does not support align, border, height, hspace, vspace, and width. The functionality of these attributes should be possible using style sheet rules.

Whereas the HTML 4 specification reserves data-binding attributes such as datafld or datasrc, it is not specified for <img>, although Internet Explorer provides support for these attributes.

XHTML 1.0 requires a trailing slash for this element: <img />.

Under future versions of XHTML such as 2, <img> may be dropped in favor of <object>.

(X)HTML Elements
CSS Properties
Previous: ilayer Next: input
< Home | About | Chapters | Examples | Errata | Reference | Site Map >