The img tag in HTML

The meaning of the img tag in HTML

The img tag is used to display an image file in an HTML document. The img element is the simplest way to display a static image on a page. It is usually used when the image is part of the content (as opposed to using it as part of a page design).

The necessary attributes for the img tag are: src – specifying the file address (URL); alt – alternative text displayed when the image is not loaded.

<img src="URL" alt="text instead of images">
<img src="image.png" alt="image description">
mandatory attributes of the img tag

It is possible to use an image of the img tag as a link when placing it inside the a tag. Add interactivity to the content by applying the img element in the form of image maps, when the active areas are highlighted by overlaying references to the image. The appearance of the map does not differ from the image: you can split it into invisible zones of different shapes to insert links.

<a href=""><img src="image.png" width="320" height="280" alt="site"></a>
nesting of the img tag within the a tag

The attributes of the tag img

srcspecifies the URL of the displayed image
altdefines the alternative text that is presented instead of the image
heightdefines the internal height of the image file in pixels
widthspecifies the internal width of the image, in pixels
usemapsets the client-side image map to be used with the image
ismapdefines the image as an image map on the server side
longdescdefines the URL at which you can find additional information about the image
crossoriginspecifies that CORS headers should be used in the HTTP request, and specifies whether credentials should be used
srcsetDefines multiple sizes of the same image, allowing the browser to select the appropriate image source

The srcset attribute should be used to display the image more correctly on screens with different widths and window sizes.

Leave a Comment

Your email address will not be published. Required fields are marked *