CHAPTER 10
Beginner
HTML Audio and Video Elements
Updated: May 10, 2026
5 min read
# HTML Audio and Video Elements
1. Introduction
Before HTML5, embedding video or audio required clunky third-party plugins like Flash. Today, HTML provides native, fast, and accessible<audio> and <video> tags that work perfectly out of the box.
2. Learning Objectives
-
Embed audio files using
<audio>.
-
Embed video files using
<video>.
- Add controls, autoplay, and looping functionality.
- Provide fallback content for older browsers.
3. Detailed Explanations
The <audio> Element
To play sound (MP3, WAV, OGG), use the <audio> tag. You must include the controls attribute, otherwise, the player will be invisible!
html
*Note: Providing multiple <source> tags ensures the browser can pick the format it supports best.*
The <video> Element
The <video> tag works similarly but includes visual attributes like width, height, and a poster image.
html
Media Attributes
You can customize the player behavior using these boolean (true/false) attributes:-
controls: Shows play, pause, and volume buttons.
-
autoplay: Starts playing instantly (Note: Browsers block this unless it is also muted!).
-
muted: Starts with the volume at 0.
-
loop: Restarts the media automatically when it finishes.
-
poster(Video only): Shows an image before the user hits play.
html
4. Mini Project: Media Showcase
Let's build a mini media portfolio.
html
5. MCQs
Q1: Which attribute is required to show the play/pause buttons on an audio element? A) buttons="true" B) show-ui C) controls D) interface *Answer: C*6. Summary
HTML5 makes rich media incredibly simple. Always use thecontrols attribute for user accessibility. If you want a video to autoplay (like a background video), you MUST also include the muted attribute, or modern browsers will block it.