In HTML, images are embedded in a webpage using the <img>
tag.
<img src="URL" alt="Description of the image">
Try it yourself
<img>
Tagsrc
:
src
attribute defines the path to the image file.alt
:
alt
attribute provides alternative text for the image, which is important for screen readers used by visually impaired users. It also appears if the image cannot be displayed.alt="A picture of a mountain at sunset"
width
and height
:
width="300"
or height="200"
title
:
title
attribute provides additional information about the image, often displayed as a tooltip when the user hovers over the image.title="Sample Image"
loading
:
loading
attribute allows you to defer the loading of off-screen images until the user scrolls near them (lazy loading), improving performance.lazy
(default), eager
.loading="lazy"
srcset
and sizes
:
srcset
: Specifies different images for different screen resolutions.sizes
: Specifies which image size to use based on the display size.Try it yourself