WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML <img> Tag


Example

How to insert an image:

<img src="smiley.gif" alt="Smiley face" height="42" width="42">
Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

<img> Tags define images in HTML pages.

<img> Tags have two required attributes: src and alt.

Note: Technically, images are not inserted into HTML pages, but instead are linked to HTML pages. <img> The purpose of the label is to create a placeholder for the referenced image.

Tip: <a> Nested in tags <img> Tags, links to images added to another document.

Browser Support

Element
<img> Yes Yes Yes Yes Yes Yes

Differences Between HTML 4.01 and HTML5

The following attributes: align, border, hspace, and vspace are not supported in HTML5.


Differences Between HTML and XHTML

In HTML the <img> tag has no end tag.

In XHTML the <img> tag must be properly closed.


Attributes

= New in HTML5.

attribute value description
align top
bottom
middle
left
right
Not supported in HTML5. HTML 4.01 is obsolete. Specifies how to arrange images based on surrounding text.
alt text Specifies alternate text for the image.
border pixels Not supported in HTML5. HTML 4.01 is obsolete. Specifies the border around the image.
crossorigin New anonymous
use-credentials
Set the cross-domain properties of the image
height pixels Specifies the height of the image.
hspace pixels Not supported in HTML5. HTML 4.01 is obsolete. Specifies the margins to the left and right of the image.
ismap ismap Specifies an image as a server-side image map.
longdesc URL Not supported in HTML5. HTML 4.01 is obsolete. A URL to a document containing a long image description.
src URL Specifies the URL of the displayed image.
usemap #mapname Define an image as a client-side image map.
vspace pixels Not supported in HTML5. HTML 4.01 is obsolete. Specifies the margins at the top and bottom of the image.
width pixels specifies the width of the image.