The HTML <img> tag is used to add images inside the webpage/website. Nowadays website does not directly add images to a web page, as the images are linked to web pages by using the <img> tag which holds space for the image. The
<img> tag has two required attributes:
- src – It specifies the path to the image
- alt – It specifies an alternate text for the image if the image for any reason cannot be displayed on the webpage.
Syntax of image tag:
<img src=”” alt=”” width=”” height=””>
Attributes used in image tag :
|Specifies the path to the image.
|Provides alternate text for the image, useful for informing users about the image and displaying in case of network issues.
|Allows importing images from third-party sites with cross-origin access for use with canvas.
|Specifies the height of the image.
|Specifies the width of the image.
|Specifies an image as a server-side image map.
|Specifies whether a browser should defer loading of images until certain conditions are met or load an image immediately.
|Specifies a URL to a detailed description of an image.
|Specifies which referrer information to use when fetching an image (e.g., no-referrer, no-referrer-when-downgrade, origin).
|Specifies image sizes for different page layouts.
|Specifies a list of image files to use in different situations.
|Specifies an image as a client-side image map.
Example 1: The implementation of the <img> tag along with src, width, height, and alt attributes.
img src with width and height
Example 2: The implementation of the style attribute to add a border to the image.
image source with border
- Google Chrome 1
- Edge 12
- Firefox 1
- Opera 15
- Safari 1
Share your thoughts in the comments
Please Login to comment...