Open In App

HTML src attribute

Last Updated : 27 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The HTML src attribute specifies the URL or file path of an external resource, such as an image, video, audio file, or script, to be embedded or referenced within a webpage.

Syntax:

<element  src="url">

HTML src attribute Supported tags

TagDescription
<audio>Embeds sound content for playback in a webpage.
<embed>Integrates external applications or content.
<iframe>Embeds another HTML document within the current one.
<frame>Deprecated. Divides the browser window.
<img>Embed images for display.
<input>Creates interactive control elements in forms.
<script>Embeds or links to external scripts.
<source>Specifies alternative media resources.
<track>Provides text tracks for multimedia elements.
<video>Embeds video content for playback in a webpage.

Attribute Values

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

TermDescription
Absolute URLPoints to a resource outside the current website/domain.
Relative URLPoints to a resource within the same website/domain.

Example of HTML src attribute

Example 1: In this example we displays GeeksforGeeks heading and an audio player with multiple source files for playback control.

html
<!DOCTYPE html> 
<html> 
<head> 
    <title> 
        HTML audio src Attribute 
    </title> 
</head> 

<body style="text-align:center;"> 
    
    <h1 style="color:green">
          GeeksforGeeks
      </h1> 
    
    <h2> 
        HTML audio src Attribute 
    </h2> 
    
    <audio controls muted> 
        <source src="GFG.mp3" type="audio/mp3"> 
        <source src="GFG.ogg" type="audio/ogg"> 
    </audio> 
</body> 
</html>                     

Output:  

Example 2: In this example image linked via the “src” attribute with an alternative text.

html
<!DOCTYPE html> 
<html> 

<head> 
    <title> 
        HTML img src Attribute 
    </title> 
</head> 

<body> 
    <h1 style="color:green">
          GeeksforGeeks
      </h1> 

    <h2>HTML img src Attribute</h2> 

    <img src= 
"https://media.geeksforgeeks.org/wp-content/uploads/20190506164011/logo3.png"
         alt="GeeksforGeeks logo"> 
</body> 
</html> 

Output:  


Supported Browsers: The browsers supported by HTML src attribute are listed below: 


Similar Reads

Why card images use data-src (not src) for image in Bootstrap 4 ?
Bootstrap 4 card images use src in image tags to providing the location to be loaded in the given image tag and data-src to provide additional information that can be used by JavaScript for improving the users' experience. For data-src and src tag we can conclude as follows: src: If you want to load and display a particular image, then use .src to
3 min read
How href attribute is different from src attribute in HTML ?
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 (&lt;a&gt;) elements, points to the destination of hyperlinks, facilitating navigation. The src attribute, used with elements like &lt;img&gt; and &lt;script&gt;, specifies
1 min read
HTML | &lt;frame&gt; src Attribute
The HTML &lt;frame&gt; src Attribute is used to specifies the document URL which is used to display in the frame. Syntax: &lt;frame src="URL"&gt; Attribute Values: It contains single value URL which specifies the source of the document. The possible value of the URL is: absolute URL: It points to another website. relative URL: It points to a file w
1 min read
HTML | &lt;input&gt; src Attribute
The HTML &lt;input&gt; src Attribute is used to specify the URL of the image to be used as a submit button. This attribute can only be used with &lt;input type="image"&gt;.Syntax: &lt;input src="URL"&gt; Attribute Values: It contains a single value URL that specifies the link of the source image. There are two types of URL links which are listed be
1 min read
HTML | &lt;video&gt; src Attribute
The HTML &lt;video&gt; src Attribute is used to specify the URL of the video file. This attribute uses Ogg file on Firefox, Opera and Chrome browsers and MPEG4 file on Internet Explorer and Safari browsers. This attribute is new in HTML5. Syntax: &lt;video src="URL"&gt; Attribute Values: It contains a single value URL which specifies the link of so
1 min read
HTML | &lt;track&gt; src Attribute
The HTML &lt;track&gt; src Attribute is used to specify the URL of the track. Syntax: &lt;track src="subtitles_en.vtt"&gt; Attribute Values: It contains single value URL which is used to specify the URL of the track. Below example illustrates the use of src attribute in &lt;track&gt; element. Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;l
1 min read
HTML | &lt;script&gt; src Attribute
The HTML &lt;script&gt; src Attribute is used to specify the URL of external JavaScript file. The External JavaScript file is used to run on the same script on several pages on a website. We can save the JavaScript file with an extension of .js. We can refer the external script using the src attribute of the &lt;script&gt; element. Syntax: &lt;scri
1 min read
HTML | &lt;iframe&gt; src Attribute
The HTML &lt;iframe&gt; src attribute is used to specify the URL of the document that are embedded to the &lt;iframe&gt; element. Syntax: &lt;iframe src="URL"&gt; Attribute Values: It contains single value URL which specifies the URL of the document that is embedded to the iframe. There are two types of URL link which are listed below: Absolute URL
1 min read
HTML | &lt;audio&gt; src Attribute
The HTML &lt;audio&gt; src attribute is used to specify the URL of the audio files. We should use the Mp3 file for play the audio in the Internet Explorer and Safari Browsers. The source element can be used to add audio files to a webpage to work in all the Browsers. Syntax: &lt;audio src="URL"&gt; Attribute Values: It contains single value URL whi
1 min read
HTML | &lt;source&gt; src Attribute
The HTML &lt;source&gt; src attribute is used to specify the URL of the media resource. The source element is used as a child element of the &lt;audio&gt; and &lt;video&gt; element. Syntax: &lt;source src="URL"&gt; Attribute Values: It contains single value URL which specifies the URL of the media resource. There are two types of URL link which are
1 min read