HTML Image

HTML <img/> tag is used to show the images on the web page. HTML image tag does not require the closting tag. HTML image tag contain only attributes to specify it's sources and alternative text and extra.

Example of HTML image.

<h3>HTML Image Example</h3>  
<img src="bird_chirping.jpg" alt="Bird Chirping" />
  Try it Yourself

Attributes of HTML img tag

src

It is a required attribute that express the source or path of the image. It tell the browser where to look for the image on the server.The location of image may be on the same directory or another server.

Example :

<img src="bird_chirping.jpg" />
  Try it Yourself

alt

The alt attribute tells an alternate text for the image if the image not loaded or may be crashed on browser the alternative text should be shown. The value of the alt attribute describe the image in words. The alt attribute is mostly used for SEO prospective.

Google Search Engine in image tab images are search by the alternative text.

Example :

<img src="girl_image.jpg" alt="Girl Image" />
  Try it Yourself

width

The width attribute is used to specify the width of the image. it is an optional attribute and we can also set width of image using CSS.

Example :

<img width="300" src="fruits_basket.jpg" alt="Fruits Basket" />
  Try it Yourself

height

The height attribute is used to specify the height of the image. it is an optional attribute and we can also set height of image using CSS.

Example :

<img height="200" width="300" src="fruits_basket.jpg" alt="Fruits Basket" />
  Try it Yourself

We can use an image as a link

Example :

<a href="sample.html" >
<img src="girl_image.jpg" alt="Girl Image" style="width:200px;height:160px;">
</a>
  Try it Yourself
Element Chrome Browser Chrome ie browser IE firefox Firefox opera Opera safari Safari
<img> Yes Yes Yes Yes Yes