Source src attribute

Definition and usage

src Sets or returns the value of the src attribute in the <source> element.

<source> src attribute Specifies the URL of the media file to be played.

Note:IE 8 and earlier versions only return the filename (e.g., song.mp3), not the URL (https://www.codew3c.com/song.mp3).

See also:

HTML Reference Manual:HTML <source> Tag

Example

Return the URL of the media file:

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

Try it yourself

Syntax

Return the src attribute:

sourceObject.src

Set the src attribute:

sourceObject.src = URL

Attribute value

Value Description
URL

Specifies the URL of the media file.

Possible values:

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

Technical Details

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

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Related Pages

HTML Reference Manual:HTML <source> src Attribute