The image tag in HTML is used to display images on a web page. Images make websites more attractive and help present information in a visual form.
What is the Image Tag
The image tag is written as <img>. It is an empty tag, which means it does not have a closing tag.
Basic Structure
The image tag uses attributes to define the image source and description.
Example of Image Tag
<img src=”image.jpg” alt=”Sample Image”>
src Attribute
The src attribute is used to define the path or location of the image file. It tells the browser where the image is stored.
alt Attribute
The alt attribute provides alternative text for the image. If the image does not load, this text will be shown. It also helps screen readers and improves SEO.
Image Paths
Images can be added using different types of paths depending on where the file is stored.
Relative Path Example
<img src=”images/photo.jpg” alt=”Photo”>
Absolute Path Example
<img src=”https://example.com/photo.jpg” alt=”Online Image”>
Why Images are Important
Images make web pages more engaging and easier to understand. They improve the design and help users connect with the content.
Summary
The image tag is used to insert images in HTML pages. It uses the src attribute to load the image and the alt attribute to describe it.