HTML Tag Reference - HTML tag <img>








This <img> element controls how a picture is displayed on a web page.

Browser compatibility

<img> Yes Yes Yes Yes Yes

What's new in HTML5

The attributes align, border, hspace, longdesc, and vspace are deprecated in HTML5.

Attribute

Attribute Value Description
align top
bottom
middle
left
right
Not supported in HTML5.
Set the alignment of an image
alt text Set an alternate text for an image
border pixels Not supported in HTML5.
Set the border width
crossorigin anonymous
use-credentials
Allow images from third-party sites used in canvas
height pixels Set the height of an image
hspace pixels Not supported in HTML5.
Set the whitespace on left and right side of an image
ismap ismap Set an image as a server-side image-map
longdesc URL Not supported in HTML5.
Set the URL to a document containing a long description for the image
src URL the URL of an image
usemap #mapname Set an image as a client-side image-map
vspace pixels Not supported in HTML5.
Set the whitespace on top and bottom of an image
width pixels Set the width of an image




Global Attributes

The <img> tag supports the Global Attributes in HTML.

Event Attributes

The <img> tag supports the Event Attributes in HTML.

Default CSS Settings

img { 
    display: inline-block;
}

Example

A demo showing how to use <img> tag.

<html>
<body>
     <img src="http://java2s.com/style/download.png" 
          alt="The Capitan">
</body>
</html>

Click to view the demo