HTML img Tag

HTML img tag: The HTML<img>tag specifies an image in an HTML page. The HTML img tag has two required attributes i.e. src and alt. Images are not technically inserted into an HTML page, images are linked to HTML pages. The <img> tag creates a holding space for the referenced image. In HTML 4.01 align, border, hspace and vspace attributes are supported. But whereas in HTML 5 align, border, hspace, and vspace attributes are not supported.

 HTML<img>Tag

This HTML <img> tag supports both the global and the event attributes.

Syntax:<img src=”url” alt=”some_text”>

‘src’ attribute

src stands for source. Every image has an src attribute which tells the browser where to find the image you want to display. The URL of the image provided points to the location where the image is stored.

‘alt’ attribute

If the image cannot be displayed then the alt attribute acts as an alternative description for the image. The value of the alt attribute is an user-defined text.

Browser compatibility

The HTML<img>tag is supported by different types of browsers.

  • Chrome
  • Firefox
  • Opera
  • Safari
  • Internet Explorer

Example:

<!DOCTYPE html>
<html>
<body>
<img src="https://tutorials.freshersnow.com/wp-content/uploads/2019/04/HTML-Tutorial.jpg" alt="logo" width="42" height="42">
</body>
</html>

Output:
HTML img tag

 

Attributes that are supported by the <img> tag

Attribute Value Description
align left
center
right
middle
bottom
Specifies the alignment of an iframe according to surrounding elements
alt text Specifies an alternate text for an image
border pixels Specifies the width of the border around an image
height pixels Specifies the height of an image
hspace pixels Specifies the whitespace on left and right side of an image
ismap ismap Specifies an image as a server-side image-map
longdesc URL Specifies a URL to a detailed description of an image
sizes Specifies image sizes for different page layouts
src URL Specifies the URL of an image
srcset URL Specifies the URL of the image to use in different situations
usemap pixels Specifies an image as a client-side image-map
vspace pixels Specifies the whitespace on top and bottom of an image
width pixels Specifies the width of an image