THE WORLD'S LARGEST WEB DEVELOPER SITE

HTML src Attribute


Definition and Usage

The src attribute specifies the location (URL) of the external resource.


Applies to

The src attribute can be used on the following elements:

Elements Attribute
<audio> src
<embed> src
<iframe> src
<img> src
<input> src
<script> src
<source> src
<track> src
<video> src

Examples

Audio Example

An audio player:

<audio src="horse.ogg" controls>
Your browser does not support the audio element.
</audio>
Try it Yourself »

Embed Example

An embedded flash animation:

<embed src="helloworld.swf">
Try it Yourself »

Iframe Example

An <iframe> in its simplest use:

<iframe src="/default.asp"></iframe>
Try it Yourself »

Img Example

An image is marked up as follows:

<img src="smiley.gif" alt="Smiley face">
Try it Yourself »

Input Example

An HTML form with an image that represents the submit button:

<form action="/action_page.php">
  First name: <input type="text" name="fname"><br>
  <input type="image" src="submit.gif" alt="Submit">
</form>
Try it Yourself »

Script Example

Point to an external JavaScript file:

<script src="myscripts.js"></script>
Try it Yourself »

Source Example

An audio player with two source files. The browser should choose which file (if any) it has support for:

<audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Try it Yourself »

Track Example

A video with two subtitle tracks:

<video width="320" height="240" controls>
  <source src="forrest_gump.mp4" type="video/mp4">
  <source src="forrest_gump.ogg" type="video/ogg">
  <track src="subtitles_en.vtt" kind="subtitles" srclang="en" label="English">
  <track src="subtitles_no.vtt" kind="subtitles" srclang="no" label="Norwegian">
</video>

Video Example

Play a video:

<video src="movie.ogg" controls>
  Your browser does not support the video tag.
</video>
Try it Yourself »

Browser Support

The src attribute has the following browser support for each element:

Element
audio 4.0 9.0 3.5 4.0 10.5
embed Yes Yes Yes Yes Yes
iframe Yes Yes Yes Yes Yes
img Yes Yes Yes Yes Yes
input 1.0 2.0 1.0 1.0 1.0
script Yes Yes Yes Yes Yes
source 4.0 9.0 3.5 4.0 10.5
track 18.0 10.0 31.0 6.0 15.0
video 4.0 9.0 3.5 4.0 10.5