Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

HTML DOM Source src Property

Source src Property

Source Object Reference The Source object

Example

Return the URL of the media file:

var x = document.getElementById("mySource").src;

x The output is:

https://www.runoob.com/try/demo_source/horse.mp3

Try it »


Definition and Usage

The src property sets or returns the value of the src attribute in the element.

The src property specifies the URL of the media file to be played.

Note: The element is new in HTML5.

**Note:** Internet Explorer 8 and earlier versions return only the file name (for example, horse.mp3), rather than the full URL (for example, http://www.w3cschool.cc/jsref/horse.mp3).


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src property.


Syntax

Return the src attribute:

sourceObject

.src

Set the src attribute:

sourceObject

.src=

URL

Attribute values

Value Description
URL Specifies the URL of the media file.

Possible values:

  • Absolute URL - points to another website (such as href="http://www.example.com/horse.mp3")
  • Relative URL - points to a file within the website (such as href="horse.mp3")
  • |

    Technical Details

    Return Value: A string representing the URL of the media file. Returns the full URL, including the protocol (such as http://).

    Related Articles

    HTML Reference Manual:HTML src property


    Source Object Reference The Source object