English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML Tag Reference

HTML Audio/Video DOM duration attribute

The duration attribute gives the length of the media in seconds. If no media data is available, it is zero.

 HTML Audio/Video DOM Reference Manual

Online Example

Get the current video length:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>HTML Audio/video duration attribute usage-Basic Tutorial(oldtoolbag.com)</title>
</head>
<body>
<button onclick="getVidDur()" type="button">Get the current video length: </button>
<br> 
<video id="video1" controls="controls">
  <source src="mov_bbb.mp4" type="video/mp4">
  <source src="mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video tag.
</video>
<script>
myVid=document.getElementById("video1");
function getVidDur()
{ 
  alert(myVid.duration);
} 
</script> 
</body>
</html>
Test to see ‹/›

Definition and Usage

The duration property returns the current audio/The length of the video, in seconds.

If the audio is not set/If the length of the video is not set, it returns NaN (Not a Number).
Note: This property is read-only.

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the duration property.

Note:Internet Explorer 8 and earlier versions do not support this property.

Syntax

audio|video.duration

Technical Details

Return value:Numeric value representing the audio/The length of the video, in seconds.
 HTML Audio/Video DOM Reference Manual