The HTMLMediaElement.duration property gives the length of the media in seconds. If no media data is available, the value NaN is returned. If the media is not known to be bound (for example, live streaming), then the value Infinity is returned.


var myDuration = audioOrVideo.duration


A double. If the media data is available but the length is unknown, this value is NaN. If the media is streamed and has no predefined length, the value is Inf.


var obj = document.createElement('video');
console.log(obj.duration); // NaN


Specification Status Comment
HTML Living Standard
The definition of 'HTMLMediaElement.duration' in that specification.
Living Standard  
The definition of 'HTMLMediaElement.duration' in that specification.
Recommendation Initial definition.

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
durationChrome Full support 43Edge Full support 12Firefox Full support 3.5IE Full support 9Opera Full support YesSafari Full support 6WebView Android Full support 43Chrome Android Full support 43Edge Mobile Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?


Full support  
Full support
Compatibility unknown  
Compatibility unknown

See also

Document Tags and Contributors

Last updated by: sideshowbarker,