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

HTML DOM Audio src attribute

Audio src attribute

Audio Object Reference Audio object

Example

Get the URL of the audio file:

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

x

The output is:

http://www.w3cschool.cc/try/demo_source/horse.ogg

Try it »


Definition and Usage

The src attribute sets or returns the current source of the audio.

The src attribute specifies the location (URL) of the audio file.


Browser support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the src attribute. But not all major browsers support the defined audio file formats.

Note: Internet Explorer 8 and earlier IE versions are not supported.


Syntax

Return the src attribute:

audioObject

.src

Set the src attribute:

audioObject

.src=

URL

Attribute values

Value Description
URL

Specifies the URL of the audio source.

Possible values:

  • Absolute URL - points to another website (e.g. src="http://example.com/movie.ogg")
  • Relative URL - points to a file within the website (e.g. src="/data/movie.ogg")
  • |

    Technical Details

    Return Value: String representing the URL of the audio file. Returns the actual URL, including the protocol part (e.g. http://)

    Related pages

    HTML Reference Manual: HTML


    Audio Object Reference Audio object