W3cubDocs

/Web APIs

HTMLMediaElement: duration property

The read-only HTMLMediaElement property duration indicates the length of the element's media in seconds.

Value

A double-precision floating-point value indicating the duration of the media in seconds. If no media data is available, the value NaN is returned. If the element's media doesn't have a known duration—such as for live media streams—the value of duration is +Infinity.

Examples

js

const obj = document.createElement("video");
console.log(obj.duration); // NaN

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
duration 3 12 3.5 9 ≤12.1 3.1 ≤37 18 4 ≤12.1 3 1.0

See also

© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/duration