HTMLVideoElement
Video Element
Represents a <video> tag. Embeds a video player. Control playback, volume, and position entirely through JavaScript.
<video
src="clip.mp4"
controls
></video>
Key Properties
| Property | Type | Description |
|---|---|---|
| src | string | URL of the video file. |
| currentTime | number | Current playback position in seconds. Readable and writable. |
| duration | number | Total video length in seconds. Read-only. |
| volume | number | Volume from 0.0 (silent) to 1.0 (full). |
| muted | boolean | Mutes/unmutes without changing volume level. |
| paused | boolean | True if the video is not playing. Read-only. |
| playbackRate | number | Playback speed. 1 = normal, 2 = double speed, 0.5 = half speed. |
Common Methods
| Method | Returns | Description |
|---|---|---|
| play() | Promise | Starts playback. Returns a Promise (can fail if browser blocks autoplay). |
| pause() | void | Pauses playback. |
Quick Examples
JS
const video = document.querySelector('video');
// Custom play/pause button
document.querySelector('#btn').addEventListener('click', () => {
if (video.paused) video.play();
else video.pause();
});
// Progress bar update
video.addEventListener('timeupdate', () => {
const pct = (video.currentTime / video.duration) * 100;
document.querySelector('#progress').style.width = pct + '%';
});
// Seek on click
document.querySelector('#progress-bar').addEventListener('click', (e) => {
const rect = e.target.getBoundingClientRect();
const pct = (e.clientX - rect.left) / rect.width;
video.currentTime = pct * video.duration;
});Related Elements
Related Properties
Related Methods