HTML <img> tag

HTML <img> tag

The <img> tag is used to add an image into a document.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <img src="books.png"> </body> </html>

Attributes

The following are the attributes of <img> tag. Also try Global attributes.

AttributeValueExplanation
alttextSpecifies an alternate text for an image.
crossorigin
  • anonymous
  • use-credentials
Allow images from third-party sites that allow cross-origin access to be used with canvas without being "tainted".
heightpxSpecifies the height of an image.
ismap-Specifies that the image is part of a server-side map.
sizes(media) px,pxSpecifies image sizes for different media condition.
srcURLSpecifies the URL of the image (source).
srcset"URL, URL, ..."Specifies an array of possible URL's for an image.
usemap#idSpecifies the partial URL (starting with #) of an image-map associated with the element.
widthpxSpecifies the width of an image.

Deprecated Attributes

The following attributes should not be used in any case.

AttributeValueExplanation
align
  • top
  • middle
  • bottom
  • left
  • right
Specifies the alignment of the image.
borderpxSpecifies the border of the image.
hspacepxSpecifies the white space to insert to the left and right sides of the image.
longdesc
  • URL
  • URL#id
Specifies a link to a more detailed description of the image.
nametextSpecifies a name for the image.
vspacepxSpecifies the white space to insert to the top and bottom side of the image.

Reminder

Hi Developers, we almost covered 99.5% of HTML Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in HTML.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Meet the Author