×

Html & Html5

The World's best Software Development Study Portal

HTML image tag


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:


 imalayas


Some of the other attributes of img tag are:

  1. alt
  2. width
  3. 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:


Himalayas


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:


Let's understand this by the following example:


<h2> HTML IMage Example </h2>

<img src="image/himalayas.jpg" width="900px" height="500px">

Output: