HTML images are one of the most common elements used in web design. The HTML img
tag is used to embed images in a web page. The tag requires a source attribute, src
, that specifies the URL of the image file.
Here is an example of how to use the img
tag:
<img src="image.jpg" alt="A beautiful landscape">
In this example, the src
attribute points to an image file called “image.jpg”. The alt
attribute provides a text description of the image, which is displayed if the image cannot be loaded or if the user is using a screen reader.
It is also possible to specify the width and height of an image using the width
and height
attributes. For example:
<img src="image.jpg" alt="A beautiful landscape" width="500" height="300">
This will display the image with a width of 500 pixels and a height of 300 pixels.
It is also possible to use the CSS to style the images. for example :
<img src="image.jpg" alt="A beautiful landscape" class="img-responsive">
and in CSS :
.img-responsive{
width: 100%;
height: auto;
}
This will make the image responsive to the screen size.
In conclusion, the HTML img
tag is a powerful tool for adding images to a web page. It allows you to specify the source of the image, as well as its size and alternative text. And you can use CSS to style the images and make it responsive to the screen size.