THE WORLD'S LARGEST WEB DEVELOPER SITE

Source src Property

❮ Source Object

Example

Return the URL of a media file:

var x = document.getElementById("mySource").src;
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 (https://www.w3schools.com/jsref/horse.mp3).


Browser Support

Property
src Yes Yes Yes Yes Yes

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