Open In App

How href attribute is different from src attribute in HTML ?

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In HTML5, the href and src attributes play distinct roles in defining paths or URLs, each associated with specific HTML elements. The href attribute, commonly found in an anchor (<a>) elements, points to the destination of hyperlinks, facilitating navigation. The src attribute, used with elements like <img> and <script>, specifies the source URL for embedding external content like images, scripts, or multimedia.

href Attribute

  • Usage: The href attribute is primarily associated with hyperlinks (<a> anchor elements) and is used to define the URL or path to the linked resource.
  • Functionality: It specifies the destination of the hyperlink, whether it’s a web page, an external resource, or an internal anchor within the same page.

Syntax

<a href="https://www.example.com">Visit Example Website</a>

src Attribute

  • Usage: The src attribute is commonly used with elements like <img>, <script>, <iframe>, and others. It specifies the source URL or path for embedding external content.
  • Functionality: It defines the source of the content to be embedded, whether it’s an image, a script, an audio or video file, etc.

Syntax

<img src="image.jpg" alt="Description">

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads