HTML src Attribute

The src attribute specifies the URL or path of a resource file, such as an image, audio, or video file. Elements that accept this attribute include <img>, <script>, <iframe>, <audio>, <video>, <embed>, <input>, <source>, and <track>.

Example

#

A src attribute on an <img> element.
The attribute references an image of a Van Gogh painting.

Van Gogh, Self-portrait
<img src="/img/html/vangogh-lg.jpg"
     alt="Van Gogh, Self-portrait" />

For additional details see our HTML img src Reference.


Using src

The src attribute specifies the URL or path of the resource file to be loaded.

The file will then be displayed (image), played (audio, video), or embedded (iframe, embed).

The src URL can be internal (same website) or external (from another website).


Syntax

<tagname src="URL" />

Values

#

Value Description
URL URL or path of the source file.

Elements that accept src

These elements accept the src attribute.

Elements Description
<img> Specifies an HTML image -- see example above
<script> Adds a script to the page.
<iframe> Displays a page inside the current page.
<audio> Specifies an audio player.
<video> Specifies a video player.
<embed> Embeds an object into the page.
<input> Creates an input field.
<source> Defines the audio, video, or picture source.
<track> Adds a text track, such as subtitles, to an audio or video player.

<script> with src

A src attribute on a <script> element.
The attribute references a JavaSript file.

<script src="/tutorial/myscript.js">
</script>

For additional details see our HTML script src Reference.


<iframe> with src

A src attribute on an <iframe> element.
The attribute references a page to be placed inside the frame.

<iframe src="https://www.wikipedia.org/wiki/Vincent_van_Gogh"
        style="width:100%;height:500px;">
</iframe>

For additional details see our HTML iframe src Reference.


<audio> with src

A src attribute on an <audio> element.
The attribute references an audio file.

<audio src="/media/epic.mp3" controls>
</audio>

For additional details see our HTML audio src Reference.


<video> with src

A src attribute on a <video> element.
The attribute references an video file.

<video src="/media/movie.mp4" controls
       width="320" height="240">
</video>

For additional details see our HTML video src Reference.


<embed> with src

A src attribute on an <embed> element.
The attribute references an image file.

<embed src="/img/html/vangogh-bedroom.jpg">

For additional details see our HTML embed src Reference.


<input> with src

A src attribute on an <input> element.
The attribute references an image file.






<form action="/tutorial/action.html">
  <label for="firstname">First name</label><br />
  <input type="text" id="firstname" name="firstname"><br />
  <label for="lastname">Last name</label><br />
  <input type="text" id="lastname" name="lastname"><br /><br />

  <input type="image" src="/img/html/arrow.png" 
         width="40" height="40" alt="Submit">
</form>

For additional details see our HTML input src Reference.


<source> with src

Two <source> tags with src attributes.
The attributes reference different audio files.

<audio controls>
  <source src="/media/epic.mp3" type="audio/mpeg">
  <source src="/media/epic.wav" type="audio/wav">
</audio>

For additional details see our HTML source src Reference.


<track> with src

A src attribute on a <track> element.
The attribute references a file with a text track for Spanish subtitles.

<video controls="controls" width="320" height="176">
  <source src="/media/godfather.mp4" type="video/mp4" />
  <source src="/media/godfather.ogg" type="video/ogg" />
  <track src="/media/godfather.srt" kind="subtitles" srclang="es" label="Spanish" />
</video>

For additional details see our HTML track src Reference.


Browser support

Here is when src support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like



Guides