HTML <img> tag

The <img> tag is used to display an image on a webpage.

NOTE: The <img> tag has no end tag.

Attributes

Attribute Description Possible values
align Deprecated. Sets the alignment of an image relative to what sorrounds it top, bottom, middle, left, right
alt Required. Specifies alternative text to be displayed if the image does not load altText
border Deprecated. Sets a border around an image borderWidthNumeric
height Sets the height of the image numericValue, %
hspace Deprecated. Sets how much white space there should be on the left and right sides of an image numericValue
longdesc Specifies a URL where a long description of the image can be found theURL
src Required. Specifies the location of the image imgLocation
usemap Specifies that the image is an imagemap nameOfMap (see HTML <map> tag for more information)
vspace Deprecated. Sets how much white space there should be on the top and bottom sides of an image numericValue
width Sets the width of the image numericValue, %

Standard attributes

class, dir, id, lang, style, title, xml:lang

For more information on standard attributes, check out our HTML standard attributes reference page.

Event attributes

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

For more information on event attributes, check out our HTML event attributes reference page.

Example

<img src="/images/apple.jpg" alt="Apple" /> <img src="/images/swan.jpg" alt="Swan" height="120" width="120" /> <img src="/images/sky.jpg" alt="Sky" height="150" width="170" />
Output:
Apple Swan Sky

Tips & notes

Remember to use the alt attribute to specify alternative text to display in case the image does not load.

Use the title attribute to display some text in a tooltip when the user moves the mouse over the image.

You can use an image as a link. Check out our HTML image link example for a demonstration of this. This sure does beat those plain old boring text links! But don't overdo it...

Web Reference
  1. CSS reference
  2. RSS reference
  3. HTML reference


© Copyright 2011-2012 Landofcode.com
Terms of use | Privacy policy | Copyright information | Make a donation