In HTML, images are added to a webpage using the <img> tag.
Images make a webpage more attractive, useful, and easier to understand.
<img> tag is an empty tag. It does not have a closing tag.
HTML images are used to display pictures on a webpage. The browser reads the image path and shows the image on the screen. Images are not directly stored inside the page; they are linked through their source path.
<img src="image.jpg" alt="My Image">
The <img> tag uses attributes to define the image file and display details.
| Attribute | Purpose |
|---|---|
src |
Path or URL of the image file |
alt |
Alternative text if image cannot be displayed |
width |
Sets the width of the image |
height |
Sets the height of the image |
src Attribute
The src attribute tells the browser where the image file is located.
The path may be a local file path or an internet URL.
<img src="myimage.jpg" alt="My Image">
alt Attribute
The alt attribute provides alternate text for an image.
It is useful when the image cannot load and also helps screen readers.
<img src="india.jpg" alt="Image of India">
You can control the size of an image using the width and height attributes
or with CSS style.
<img src="img1.jpg" alt="Image 1" style="width:500px;height:600px;">
<img src="image.jpg" alt="Responsive Image" style="max-width:100%;height:auto;">
<img> tag is used to display images on a webpage.src attribute is mandatory.alt attribute improves accessibility and SEO.alt attribute for accessibility and better SEO.
Which attribute specifies the image location?