THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Source src Property

Source Object Reference Source Object

Example

Return the URL of a media file:

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

The result of x will be:

http://www.w3schools.com/jsref/horse.mp3
Try it Yourself »

Definition and Usage

The src property sets or returns the value of the src attribute in a <source> element.

The src attribute specifies the URL of the media file to play.

Note: The <source> element is new in HTML5.

Note: Internet Explorer 8 and earlier versions, only returns the file name(e.g. horse.mp3), instead of the URL (http://www.w3schools.com/jsref/horse.mp3).


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The src property is supported in all major browsers.


Syntax

Return the src property:

sourceObject.src

Set the src property:

sourceObject.src=URL

Property Values

Value Description
URL Specifies the URL of the media file.

Possible values:

  • An absolute URL - points to another web site (like href="http://www.example.com/horse.mp3")
  • A relative URL - points to a file within a web site (like href="horse.mp3")

Technical Details

Return Value: A String, representing the URL of the media file. Returns the entire URL, including the protocol (like http://)

Related Pages

HTML reference: HTML <source> src attribute


Source Object Reference Source Object