`<video>` and `<audio>` Ship With Players Built In
Media
Embed video and audio with `<video>` and `<audio>`. Add controls, multiple sources, and captions for accessibility.
What you'll learn
- Embed video with `<video>`
- Provide multiple source formats
- Add captions
<video> and <audio> embed media with native controls. No
plugin, no library.
A Basic Video
<video src="/video.mp4" controls width="640"></video> controls— show play / pause / progress / volume / fullscreenwidth/height— sized like an imageposter="/thumb.jpg"— image shown before playmuted— required forautoplayon most browsers
Multiple Sources
Different browsers prefer different formats. Provide several:
<video controls width="640">
<source src="/video.webm" type="video/webm" />
<source src="/video.mp4" type="video/mp4" />
Your browser doesn't support video.
</video> The browser picks the first format it can play. The fallback text appears only on truly ancient browsers.
Autoplay Caveats
<video autoplay muted loop playsinline></video> Modern browsers block autoplay with sound. To get reliable
autoplay, also include muted. playsinline keeps the video in
place on iOS (instead of opening fullscreen).
Captions
<video controls>
<source src="/talk.mp4" type="video/mp4" />
<track kind="captions" srclang="en" label="English" src="/talk.en.vtt" default />
<track kind="captions" srclang="es" label="Spanish" src="/talk.es.vtt" />
</video> Captions (in WebVTT format) appear in the native player. They help deaf and hard-of-hearing users — and anyone watching with the sound off.
Audio
Same idea, no width:
<audio controls src="/podcast.mp3"></audio> Or with multiple sources:
<audio controls>
<source src="/song.ogg" type="audio/ogg" />
<source src="/song.mp3" type="audio/mpeg" />
</audio> Performance
Media files are usually the biggest assets. Optimize:
- Compress with
ffmpegbefore publishing - Multiple resolutions — serve smaller files to phones
preload="metadata"to skip downloading the whole file until play
Up Next
Embedding other content with <iframe>.