It is used to display image on the web page.
HTML img tag is an empty tag that contains attributes only, closing tags are not used in HTML image tag.
Src attribute is used with image tag to provide the path for image to be displayed.
It is used as below:
Let's understand this by the following example:
<img src="image/himalayas.jpg" width="800px" >
Output:
Some of the other attributes of img tag are:
alt
width
height
alt attribute
It is used to show alternate text if image is not displayed.The value of alt attribute should describe the image.
It is used as below:
Let's understand this by the following example:
<h2> HTML alt attributes</h2>
<img src="himalayas.jpg" alt="Himalayas">
Output:
Width and Height attribute
Width attribute is used to set the width of an image.
Height attribute used to set the height of an image.It is used as below: