The HTML tag <img>
is used to embed images in a web page. It is a self-closing tag, which means it does not require a closing tag. The <img>
tag is one of the most commonly used tags in HTML, as images are an essential part of any web page.
The <img>
tag has several attributes that can be used to customize the image display. The most important attribute is the src
attribute, which specifies the URL of the image file. The alt
attribute is used to provide a text description of the image, which is displayed if the image cannot be loaded or if the user is using a screen reader. The width
and height
attributes can be used to specify the dimensions of the image in pixels. The title
attribute can be used to provide a tooltip for the image when the user hovers over it.
Here are some examples of how to use the <img>
tag:
This example shows how to embed an image in a web page:
<img src="image.jpg" alt="A beautiful sunset">
In this example, the src
attribute specifies the URL of the image file, and the alt
attribute provides a text description of the image.
This example shows how to specify the dimensions of an image:
<img src="image.jpg" alt="A beautiful sunset" width="800" height="600">
In this example, the width
and height
attributes specify the dimensions of the image in pixels.
This example shows how to add a tooltip to an image:
<img src="image.jpg" alt="A beautiful sunset" title="Click to enlarge">
In this example, the title
attribute provides a tooltip for the image when the user hovers over it.
The <img>
tag is a powerful tool for embedding images in a web page. By using the various attributes available, you can customize the display of the image to suit your needs. Whether you are creating a simple blog post or a complex e-commerce site, the <img>
tag is an essential part of any web developer's toolkit.