HTML Elements: <img>

By: Dusty Arlia
Published on January 11, 2013
Last Updated on Thursday, July 16, 2015 at 7:41 PM
Total Updates: 5

The html <img> tag is used to insert an image into your HTML document. Images are really not inserted into the webpage, rather they are linked. The <img> tag is interpreted by the rendering engine of the browser. The rendering engine creates the space needed for the image. The image is then linked using the <img> tag's src attribute.

The <img> tag has two required attributes: src and alt. The src attribute holds the URL of the image. The alt attribute is the alternate text for the image. If the image cannot be displayed, the alternate text will be shown in its place.

Here is an example of an <img> tag:

<img src="http://www.whiterootmedia.com/images/mustard_phone.jpeg" alt="Mustard Phone">

...and here's the picture:

Mustard Phone

Since images do not have content other than just the path to the image, the image tag (<img>) is called a void element.

Here is a table of the <img> tag's attributes:

Attribute Value Description
align top
bottom
middle
left
right
Not supported in HTML5. Deprecated in HTML 4.01. Specifies the alignment of an image according to surrounding elements
alt text Specifies an alternate text for an image
border pixels Not supported in HTML5. Deprecated in HTML 4.01. Specifies the width of the border around an image
crossorigin anonymous
use-credentials
Allow images from third-party sites that allow cross-origin access to be used with canvas
height pixels Specifies the height of an image
hspace pixels Not supported in HTML5. Deprecated in HTML 4.01. Specifies the whitespace on left and right side of an image
ismap ismap Specifies an image as a server-side image-map
longdesc URL Not supported in HTML5. Specifies the URL to a document that contains a long description of an image
src URL Specifies the URL of an image
usemap #mapname Specifies an image as a client-side image-map
vspace pixels Not supported in HTML5. Deprecated in HTML 4.01. Specifies the whitespace on top and bottom of an image
width pixels Specifies the width of an image

References

HTML <img> Tag. (n.d.). Retrieved January 11, 2013, from
http://www.w3schools.com/tags/tag_img.asp

Comments:

Ad:

Ad: