Image Tags In HTML

Image Tag

1) < img > tag is used to attach or embed image to our webpage.

2) It is non-container tag.

3) It is inline level element.

Attributes of Image Tag.

1) Src Attributes

It is used to provide path or location of the image.

Syntax -->(src="path")

2) Alt Attributes

It is used to provide alternative content or text to the image.

This alternative content will be displayed only when the image is not displayed due to any reason.

We should write meaningful content within alt attribute.

It is recommdend to all attribute.

Syntax -->(alt="text")

Example : < img src=" /image/dog.jpg" height="300px" width="300px" alt="Dog Image">

Path of the Image

Types of path

  • 1 Absolute path
  • 2 Relative path
  • Difference Between Absolute path and Relative path.

    Absolute path


  • 1) The path with reference to root directory is called as absolute path.
  • Example: d:/html/image/pollution.jpg <----- root directory
  • Relative path


  • 1) The path with reference to current directory is called as relative path.
  • Example: "/image/pollution.jpg" <------ this is shortest path.
  • How to attach or embed image to our webpage.

  • We need space first which is container.
  • So, for space we have image tag < img > < / img >
  • We need image and its path.
  • For this behave src attribute of < img > tag.
  • Syntax : src=""