Video duration Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Video


The duration property returns the length of a video, in seconds.

This property is read-only.

Return Value

A Number, representing the length of the video, in seconds.

If no video is set, "NaN" (Not-a-Number) is returned.

If the video is streamed and has no predefined length, "Inf" (which is Infinity) is returned.

The following code shows how to get the length of a video:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<video id="myVideo" width="320" height="240" controls>
  <source src="your.mp4" type="video/mp4">
  <source src="your.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>//from www  .  j  ava 2 m

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("myVideo").duration;
    document.getElementById("demo").innerHTML = x;


Related Tutorials