<source> lists alternative files; the browser uses the first one it supports.
Useful attributes
controls: show play, pause and volume buttons.
autoplay: start automatically (browsers usually require muted too).
loop, muted, poster (an image shown before the video plays).
For YouTube videos, use YouTube's embed code, which is an <iframe>.
💡 Key Takeaways: HTML Media: Video & Audio
Mastering HTML Media: Video & Audio helps you write clean and reliable HTML code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
HTML Media: Video & Audio Code Example
HTML
<video width="320" height="180" controls muted>
<source src="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4" type="video/mp4">
Your browser does not support the video tag.
</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 the audio element.
</audio>
Free sign-in required · Google login available
HTML Media: Video & Audio Practice Exercises
Check what you learned in “HTML Media: Video & Audio”.
/ 3 solved
Fill in the blank
Show the play/pause buttons on the video.
<video src="movie.mp4" width="320" ></video>
✓ Correct!Not quite. Try again.
Multiple choice
Which element lists alternative media files?
✓ Correct!Not quite. Try again.
Code challenge
Add an <audio> element with controls.
Write the code in the live editor. Your answer is checked automatically.