HTML img Tag
The information on this page is based on HTML version 4.01 (which is the current version of HTML). The next version, HTML 5, is currently being written. Here's a list of HTML 5 tags.
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 |
<img src="/pix/milford_sound/milford_sound_t.jpg" width="225" height="151" alt="Milford Sound in New Zealand">
|
| 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! |
|
Also see the HTML 5 version of HTML tags
Enjoy this page?
-
- Link to this page (copy/paste into your own website or blog):
- Link to Quackit using one of these banner ads.
Thanks for supporting Quackit!