HTML 4 img Tag
Also see HTML5 <img>
Tag.
This page is for the HTML 4 version of this element. For a more up to date version, see HTML5 <img>
Tag.
The HTML img
tag is used for embedding images into an HTML document.
To use this tag, the image you specify in the src
attribute needs to be available on a web server. This could be your own web server or another web server (such as PhotoBucket).
For more information on creating graphics for the web, check out the web graphics tutorial.
To link an image to another web page (or a larger version of the image), you simply nest the <img>
tag inside an <a>
tag. Here's an example of linking an image.
You can also link your image to an image map.
Example
Attributes
Attributes specific to this tag: | |
---|---|
Attribute | Description |
name | Assigns a name to an image. This is used when referencing the image with stylesheets or scripts. However, you should use the id attribute instead. |
longdesc | Specifies a URI/URL of a long description - this can elaborate on a shorter description specified with the alt attribute. |
src | Location of the image. |
Other Attributes: | |
Attribute | Description |
class | Document wide identifier. |
id | Document wide identifier |
alt | Alternate text. This specifies text to be used in case the browser/user agent can't render the image. |
title | Specifies a title to associate with the element. Many browsers will display this when the cursor hovers over the element (similar to a "tool tip"). |
style | Inline style (CSS) |
dir | Specifies the direction of the text |
lang | Language code |
ismap | For image maps. See HTML map tag |
usemap | For image maps. See HTML map tag |
align | For alignment (left, center, right, justify). |
width | Specifies the width of the image. |
height | Specifies the height of the image. |
border | Size of the image border. For no border use 0 (zero). |
hspace | Amount of white space to be inserted to the left and right of the object. Deprecated. |
vspace | Amount of white space to be inserted above and below the object. Deprecated. |
onclick | Intrinsic event (see event handlers) |
ondbclick | Intrinsic event (see event handlers) |
onmousedown | Intrinsic event (see event handlers) |
onmouseup | Intrinsic event (see event handlers) |
onmouseover | Intrinsic event (see event handlers) |
onmousemove | Intrinsic event (see event handlers) |
onmouseout | Intrinsic event (see event handlers) |
onkeypress | Intrinsic event (see event handlers) |
onkeydown | Intrinsic event (see event handlers) |
onkeyup | Intrinsic event (see event handlers) |
Try it Yourself!
Modify the code below, then click Update. See below for attributes.
HTML5 Tags
The information on this page is based on HTML version 4.01. Most modern browsers now support HTML5.
See HTML5 <img>
Tag for the HTML5 version of the above element.
See this list of HTML tags for the latest list of HTML elements.