HTML Audio & Video

HTML DOM Audio currentSrc Property

The currentSrc property returns the absolute URL of the media resource the browser has actually selected to play. It is read-only and especially useful when you provide several <source> children and want to know which one won.


Definition and Usage

The src property only reflects the src attribute you set on the element itself. When you instead use multiple <source> children, the browser picks the first supported one, and currentSrc tells you which URL it chose, resolved to an absolute address.

Syntax

mediaElement.currentSrc

It returns a string. Before a source has been selected (for example, immediately after creating the element), it may be an empty string.

Example

Discovering which <source> the browser chose
<video id="myVideo" controls>
  <source src="movie.webm" type="video/webm">
  <source src="movie.mp4"  type="video/mp4">
</video>

<script>
const video = document.getElementById("myVideo");

video.addEventListener("loadeddata", () => {
  console.log("Playing from:", video.currentSrc);
});
</script>

On a browser that supports WebM, currentSrc reports the absolute URL of movie.webm; on one that does not, it reports movie.mp4. This is the reliable way to know the effective source.

ℹ️

currentSrc is read-only. To change the playing media, set the src property (or the src attribute of a <source>) and call load(); currentSrc will then update once selection completes.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships