Open In App

What is the role of the src Attribute in <img> Tag ?

Last Updated : 26 Feb, 2024
Like Article

The src attribute in the <img> tag specifies the source URL or file path of the image to be displayed on the webpage. The browser needs to fetch and render the image correctly. Without a valid “src” attribute, the image would be missing or broken on the web page.


<img src="image-source-url" alt="alternative-text">

Attribute Values

It contains a single-value URL that specifies the link to the source image. There are two types of URL links which are listed below:

Attribute Values


Absolute URL

It points to another webpage.

Relative URL

It points to other files on the same web page.

Src Attribute

  • Source Location: The src attribute specifies the source (URL) of the image.
  • Required Attribute: It is a mandatory attribute for the <img> tag.
  • URL or Path: The value can be a URL pointing to an external image or a relative or absolute path to an image file.
  • Embedding: It can also represent embedded images by providing the data URL.
  • Fallback: If the image fails to load, the text specified in the ‘alt’ attribute is displayed instead.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads