Copyright ©

HTML <img> tag



The HTML <img> tag is used to put an image in an HTML document.

Difference between HTML and XHTML:

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

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

The align, border, hspace, and vspace attributes of the image element are deprecated in HTML as well as in XHTML.


<img src="" alt="HTML Tutorial" />

This will produce following result:

HTML Tutorial

Online Practice:

To Become more comfortable - Do Online Practice


alttextSpecifies alternate text
Specifies the aligmnet for the image.
borderpixelsDeprecated - Specifies the width of the image border.
heightpixels or %Specifies the height of the image.
hspacepixelsDeprecated - Amount of white space to be inserted to the left and right of the object.
ismapURLDefines the image as a server-side image map.
longdesctextSpecifies a URI/URL of a long description - this can elaborate on a shorter description specified with the alt attribute.
usemapURLDefines the image as a client-side image map and used alongwith <map> and <area> tags.
vspacepixelsDeprecated - Amount of white space to be inserted to the top and bottom of the object.
widthpixels or %Sets the width of an image in pixels or in %.

Standard Attributes:

classDocument wide identifier
dirSpecifies the direction of the text
idDocument wide identifier
titleSpecifies a title to associate with the element.
styleHelps to include inline casecadubf style sheet.
langSets the language code.
xml:langSets the language code.

Event Attributes:

onclickScript runs when a mouse click
ondblclickScript runs when a mouse double-click
onmousedownScript runs when mouse button is pressed
onmouseupScript runs when mouse button is released
onmouseoverScript runs when mouse pointer moves over an element
onmousemoveScript runs when mouse pointer moves
onmouseoutScript runs when mouse pointer moves out of an element
onkeypressScript runs when key is pressed and released
onkeydownScript runs when key is pressed
onkeyupScript runs when key is released

Copyright ©