HTML Images


In HTML, images are defined with the <img> tag. The <img> tag is empty, it contains attributes only, and does not have a closing tag. The src attribute defines the url (web address) of the image.

Example
<img src="demo/3.jpg" >
Try it Yourself

Output:

flower

HTML Image - Attributes

  • alt - specifies an alternate text for the image, if it cannot be displayed.
  • height - specifies the height of an image, in terms of either pixels or percentage of its actual size.
  • width - specifies the width of an image, in terms of either pixels or percentage of its actual size.
  • border - specifies border thickness in terms of pixels using border attribute. Value 0 means, no border around the image. Default border color is black.
Example
<img src="demo/1.jpg" alt="flower" width="300px" height="200px" border="6">
Try it Yourself

Output:

flower

Using image as a Link

We can also link an image with other page or we can use an image as a link. To do this, put <img> tag inside the <a> tag.

Example
<a href="demo/sample.html" target="_blank">
   <img src="demo/2.jpg" alt="flower">
</a>
Try it Yourself

Output: