HTMLadvanced 7 min
Embed sound and video with the audio and video tags, controls and fall-backs.
How to add audio and video, show player controls, offer more than one file format and provide captions.
Tutorials, podcasts and demos are media. HTML plays them natively, with no plug-ins, and gives you controls for free.
The two tags are <audio> and <video>. Useful attributes:
controls: show play, pause, volume and a progress bar.autoplay: start on load. Browsers usually block it unless the video is also muted.loop: repeat.muted: start silent.poster (video): an image shown before playing.width and height (video): size.Different browsers support different formats, so you can list several files with <source> and the browser picks the first it can play. Text inside the tag is shown to browsers that do not support it at all.
For accessibility, add captions with a <track kind="captions" src="captions.vtt" srclang="en" label="English"> element inside <video>.
<video controls> shows a player with controls. muted lets it start without sound.<source> elements offer WebM and MP4. The browser plays the first one it understands.<audio controls> works the same way, with one MP3 source.<track> for captions so deaf and hard-of-hearing users can follow.Remove muted, add loop, and press play in the preview.
controls, which leaves the visitor with nothing to click.<video> and <audio> play media natively; add controls.<source> formats.<track>.Next: page metadata and search engines.
<video controls width="320" muted>
<source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm" type="video/webm">
<source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4" type="video/mp4">
Your browser does not support video.
</video>
<p>Audio:</p>
<audio controls>
<source src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3" type="audio/mpeg">
Your browser does not support audio.
</audio>