Video duration attribute

Definition and Usage

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

Note:Different browsers return different values. In the following example, Internet Explorer, Firefox, and Chrome return 12.612". Safari returns "12.612000465393066", Opera 12 returns "12.585215419", and Opera 18 returns "12.62069".

Note:This property is read-only.

Example

Get video length:

var x = document.getElementById("myVideo").duration;

Try It Yourself

Syntax

videoObject.duration

Technical Details

Return Value:

A number representing the length of the video in seconds.

If no video is set, then 'NaN' (not a number) is returned.

If the video is streamed and does not have a predefined length, then 'Inf' (infinity) is returned.

Browser Support

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