Open In App

HTML <img> Tag

HTML <img> tag is used to insert images into a webpage. It requires the src attribute to specify the image file’s URL and supports optional attributes like alt for alternative text and width/height for dimensions. 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.

Syntax : 

<img src="" alt="" width="" height="">

HTML image Tag Attributes

Attribute Description
src Specifies the path to the image.
alt Provides alternate text for the image, useful for informing users about the image and displaying in case of network issues.
crossorigin Allows importing images from third-party sites with cross-origin access for use with canvas.
height Specifies the height of the image.
width Specifies the width of the image.
ismap Specifies an image as a server-side image map.
loading Specifies whether a browser should defer loading of images until certain conditions are met or load an image immediately.
longdesc Specifies a URL to a detailed description of an image.
referrerpolicy Specifies which referrer information to use when fetching an image (e.g., no-referrer, no-referrer-when-downgrade, origin).
size Specifies image sizes for different page layouts.
srcset Specifies a list of image files to use in different situations.
usemap 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.






<!DOCTYPE html>
<html>
 
<body style="text-align: center;">
    <h3>GeeksforGeeks logo</h3>
     
    <img src=
        width="420" height="100"
        alt="Geeksforgeeks.org">
</body>
 
</html>

Output:

HTML img tag output

Explanation:

Example 2: The implementation of the style attribute to add a border to the image.






<!DOCTYPE html>
<html>
 
<body style="text-align: center;">
    <h3>GeeksforGeeks logo</h3>
 
    <img src=
        width="420" height="100"
        alt="Geeksforgeeks.org"
        style="border:5px solid black">
</body>
 
</html>

Output:

HTML img tag output

Explanation:

Supported Browsers: 


Article Tags :