To insert an image in an HTML document, you can use the <img>
element. The <img>
element is a self-closing tag, which means it does not have a closing tag. It requires the src
attribute, which specifies the source of the image, and the alt
attribute, which specifies an alternative text for the image.
Here is an example of how to use the <img>
element to insert an image in an HTML document:
<img src="image.jpg" alt="A description of the image">
In this example, the src
attribute specifies the source of the image (image.jpg
), and the alt
attribute specifies an alternative text for the image ("A description of the image").
You can also specify the size of the image using the width
and height
attributes. These attributes accept a value in pixels or as a percentage of the available space.
<img src="image.jpg" alt="A description of the image" width="200" height="100">
In this example, the width
attribute specifies the width of the image (200 pixels), and the height
attribute specifies the height of the image (100 pixels).
You can also use the <figure>
and <figcaption>
elements to add a caption to an image. The <figure>
element represents a self-contained piece of content, and the <figcaption>
element represents the caption for the <figure>
element.
<figure>
<img src="image.jpg" alt="A description of the image">
<figcaption>A caption for the image</figcaption>
</figure>
In this example, the <img>
element inserts the image, and the <figcaption>
element adds a caption for the image.
It is generally a good practice to use descriptive and meaningful alternative texts for images, to improve accessibility and SEO (Search Engine Optimization).
0 Comments