The HTML <img> tag is used to add images into an HTML Images are not directly inserted into web pages. Images are linked to web pages and it creates a holding space for the image.
These two attributes are very important in the <img> tag src attribute this attribute is used to define the source of the image and the alt attribute with this attribute can define the alternative text of the image.
Syntax
<img src="URL" alt="alternate text">
Example
<!DOCTYPE html> <html> <head> <title>HTML IMG tag</title> </head> <body> <h2>HTML IMG tag example</h2> <img src="https://krtricks.in/wp-content/uploads/2022/05/water-lily-gb260fe708_640.jpg" alt="A beautiful flower" width="350" height="250"> </body> </html>
Output:
Attributes
Attribute | Value | Description |
---|---|---|
alt | text | It is used to define an alternative text for the image. |
crossorigin | anonymous use-credentials |
It is used to embed images from third-party sites that allow cross-origin access to be used with canvas. |
height | pixel | defines the height of an image. |
ismap | ismap | It is used to specify an image as a server-side image map. |
longdesc | URL | is used to define the long description of an image. |
referrerpolicy | no-referrer no-referrer-when-downgrade origin origin-when-cross-origin unsafe-url |
is used to specify which referrer information to use when fetching an image. |
size | sizes | it is used to define the image sizes for a different layout. |
srcset | URL-list | It is used to define a list of image files to use in different situations. |
usemap | #mapname | It is used to specify an image as a client-side image map. |
width | pixel | defines the width of an image. |
Global Attributes
The <img> tag supports the Global Attributes in HTML.
Event Attributes
The <img> tag supports the Event Attributes in HTML.
Supported Browsers
Element | Chrome | Firefox | IE | Opera | Safari |
---|---|---|---|---|---|
<img> | Yes | Yes | Yes | Yes | Yes |