English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Reference

HTML Audio/Video DOM src attribute

The src attribute reflects the value of the src attribute of the HTML media element, which indicates the URL of the media resource to be used in the element.

 HTML Audio/Video DOM Reference Manual

Online Example

Change video source:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/video src attribute usage-Basic Tutorial(oldtoolbag.com)</title>
</head>
<body>
<button onclick="changeSource()" type="button">Change video source</button>
<br> 
<video id="video1" controls="controls" autoplay="autoplay">
  <source id="mp4_src" src="mov_bbb.mp4" type="video/mp4">
  <source id="ogg_src" src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video  tag.
</video>
<script> 
myVid=document.getElementById("video1");
function changeSource()
{ 
  isSupp=myVid.canPlayType("video/mp4");
  if (isSupp=="")
  {
     myVid.src="movie.ogg";
  }
  else
  {
     myVid.src="movie.mp4";
  }
  myVid.load();
} 
</script> 
</body>
</html>
Test to see ‹/›

Definition and Usage

src attribute sets or returns audio/Current source of the video.
Source is audio/Actual location of the video file (URL)

Browser Compatibility

IEFirefoxOperaChromeSafari

Internet Explorer 10, Firefox, Opera, Chrome, and Safari support the src attribute.

Note:Internet Explorer 9 and earlier versions do not support the src attribute.

Syntax

Set src attribute:

audio|video.src=URL

Return src attribute:

audio|video.src

Attribute value

ValueDescription
URLSpecified audio/URL of the video source.

Possible values:

  • Absolute URL - Points to another website (for example, src="http:)//www.example.com/movie.ogg")

  • Relative URL - Points to a file within the website (for example, src="movie.ogg")

Technical Details

Return value:String value, the current audio/Video Source.
 HTML Audio/Video DOM Reference Manual