Skip to content

<video> - The Video Element

Media Element HTML5

The video element embeds video content into web pages. It provides built-in playback controls, supports multiple formats with fallbacks, includes accessibility features like captions, and offers a powerful JavaScript API for custom video experiences.

Result
<video src="video.mp4" controls></video>
<!-- With multiple sources and captions -->
<video controls width="640" height="360">
<source src="video.webm" type="video/webm">
<source src="video.mp4" type="video/mp4">
<track kind="captions" src="captions.vtt" srclang="en" label="English">
Your browser doesn't support video playback.
</video>

Displays the browser’s default video controls (play, pause, volume, fullscreen, progress):

Result

Specify the video player dimensions in pixels:

Result

Displays an image while the video is downloading or until the user hits play:

Result

Starts playing automatically when the page loads:

Result

Repeats the video when it reaches the end:

Result

Starts with audio muted:

Result

Controls how much video to download on page load:

<!-- Don't preload: save bandwidth -->
<video controls preload="none"
poster="poster.jpg"
src="video.mp4">
</video>

Plays video inline on mobile devices instead of fullscreen:

<!-- iOS Safari: play inline instead of fullscreen -->
<video controls playsinline width="640" height="360"
src="video.mp4">
</video>
AttributeDescriptionValuesDefault
srcVideo file URLURL-
controlsShow playback controlsBooleanfalse
widthPlayer width in pixelsNumberVideo’s intrinsic width
heightPlayer height in pixelsNumberVideo’s intrinsic height
posterPlaceholder image URLURL-
autoplayAuto-start playbackBooleanfalse
loopRepeat playbackBooleanfalse
mutedStart mutedBooleanfalse
preloadPreload strategynone, metadata, autometadata
playsinlinePlay inline on mobileBooleanfalse
crossoriginCORS settingsanonymous, use-credentials-
FormatCodecMIME TypeChromeFirefoxSafariEdge
MP4H.264video/mp4
MP4H.265/HEVCvideo/mp4✓*✓*
WebMVP9video/webm
WebMVP8video/webm
WebMAV1video/webm
OggTheoravideo/ogg
Result
Result
WEBVTT
00:00:00.000 --> 00:00:03.000
Welcome to our video tutorial.
00:00:03.000 --> 00:00:07.000
Today we'll learn about HTML5 video.
00:00:07.000 --> 00:00:11.000
Let's get started!
Result
Result
Result
Result
Result
Result
EventDescriptionWhen Fired
playPlayback startedUser clicks play or .play() called
pausePlayback pausedUser clicks pause or .pause() called
endedPlayback finishedVideo reaches the end
timeupdateCurrent time changedDuring playback (4-60 times/sec)
volumechangeVolume changedVolume or mute state changes
seekingSeeking startedUser starts seeking to new position
seekedSeeking completedSeeking operation completed
loadstartLoading startedBrowser starts loading video
loadedmetadataMetadata loadedDuration and dimensions available
loadeddataFirst frame loadedEnough data to render first frame
canplayCan start playingEnough data buffered to start
canplaythroughCan play without bufferingCan play to end without stopping
waitingWaiting for dataPlayback stopped due to buffering
errorError occurredLoading or playback error
fullscreenchangeFullscreen toggledEntered or exited fullscreen
Result
<!-- Provide captions -->
<video controls>
<source src="video.mp4" type="video/mp4">
<track kind="captions" src="captions.vtt" srclang="en" default>
</video>
<!-- Or provide transcript -->
<video controls>
<source src="video.mp4" type="video/mp4">
</video>
<details>
<summary>Video Transcript</summary>
<p>[Full text transcript of video]</p>
</details>

Ensure custom video players support keyboard navigation:

  • Space/K: Play/Pause
  • M: Mute/Unmute
  • F: Fullscreen
  • Arrow Keys: Seek forward/backward
  • Up/Down Arrows: Volume control
<video controls muted
onloadstart="if(window.matchMedia('(prefers-reduced-motion: reduce)').matches) this.pause()">
<source src="video.mp4" type="video/mp4">
</video>
Result
  1. Use appropriate resolution

    • 1080p for hero videos
    • 720p for standard content
    • 480p for thumbnails/previews
  2. Optimize bitrate

    • 5-8 Mbps for 1080p
    • 2.5-4 Mbps for 720p
    • 1-1.5 Mbps for 480p
  3. Use modern codecs

    • H.265 (50% smaller than H.264)
    • VP9 or AV1 for web
  4. Tools for compression

    • HandBrake (free, cross-platform)
    • FFmpeg (command-line)
    • Adobe Media Encoder (professional)
Result
Result
FeatureChromeFirefoxSafariEdge
Basic <video>3+3.5+4+12+
MP4 (H.264)3+21+4+12+
WebM (VP9)25+28+14.1+14+
controls3+3.5+4+12+
poster3+3.5+4+12+
<track> captions23+31+6+12+
Picture-in-Picture70+90+13.1+79+
Fullscreen API15+10+5.1+12+