HTML Image

HTML image tag is represented by <img>. It is a single tag. The <img> tag is used for showing images in the HTML document.

Example:

<img src="images/html.jpg">

Run Example

Here src is the attribute of <img> tag. It refers the source of the image. There are some other attributes for <img> tag.

  • alt attribute
  • width attribute
  • height attribute
  • align attribute
  • border attribute

The alt Attribute

The alt attribute describes the alternative text for the image. It means when the image is not displayed into the website for any reason then the text will be showed there.

Example:

<img src="images/htm.jpg" alt="This is an HTML image.">

Run Example

The width Attribute

The width attribute fixes the width of the image. For changing the default width of the image width attribute is used.

Example:

<img src="images/html.jpg" width="300px">

Run Example

The height Attribute

The height attribute fixes the width of the image. For changing the default height of the image height attribute is used.

Example:

<img src="images/html.jpg" height="300px">

Run Example

The align Attribute

The align attribute changes the alignment of the image. For changing the alignment of the image align attribute is used. The value of align attribute can be left, right or center.

Example:

<img src="images/html.jpg" align="right">

Run Example

The border Attribute

The border attribute specifies the border size of the image. But the attribute isn't supported in HTML 5. Instead of HTML5 it is used in css.

Example:

<img src="images/html.jpg" border="3">

Run Example