HTML img Tag
HTML img Tag
The img tag is used to embed an image in an HTML page. We can only link images inside the HTML document. We cannot insert images into it. The img tag specifies the space for the image in the document. It has two required attributes for best performance. Thes are:-
- src:- Specifies the path to the image
- alt:- Specifies an alternate text for the image in case the image does not appear
We have to specify width and height of an image otherwise page flickers when loads. For image linking, we have to add img tag in it.
Attribute Explanation:-
Attribute | Value | Description |
---|---|---|
alt | text | Specifies alternate text for image. |
crossorigin | anonymous use-credentials |
Allow images from third-party sites that allow cross-origin access to be used with canvas. |
height | pixels | Specifies height of an image. |
ismap | ismap | Specifies image as a server-side image map. |
loading | eager lazy |
Specifies whether browser should load an image immediately or to defer loading of images until some conditions are met. |
longdesc | URL | Specifies URL to a detailed description of image. |
referrerpolicy | no-referrer no-referrer-when-downgrade origin origin-when-cross-origin unsafe-url |
Specifies which referrer information to use when fetching an image. |
sizes | sizes | Specifies image sizes for different page layouts. |
src | URL | Specifies path to the image. |
srcset | URL-list | Specifies list of image files to use in different situations. |
usemap | #mapname | Specifies image as a client-side image map. |
width | pixels | Specifies width of an image. |
Syntax:-
Its syntax is:- < img >