The web plays media natively — no plugins. This chapter covers the <video> and <audio> elements, adding captions for accessibility, and embedding external content (a YouTube video, a map, a payment widget) with <iframe>.
Video
<video controls width="640" poster="thumbnail.jpg" preload="metadata"><source src="lesson.mp4" type="video/mp4"><source src="lesson.webm" type="video/webm">Your browser doesn't support video.</video>
controlsshows the play/pause UI;posteris the preview frame.- Multiple
<source>tags let the browser pick a format it supports. autoplayonly works when combined withmuted(browsers block sound-on autoplay).
Audio
<audio controls preload="none"><source src="podcast.mp3" type="audio/mpeg"><source src="podcast.ogg" type="audio/ogg"></audio>
Captions & tracks
Add a <track> with a WebVTT file for captions or subtitles — essential accessibility, and it helps everyone in noisy or silent settings:
<video controls><source src="lesson.mp4" type="video/mp4"><track src="captions-en.vtt" kind="captions" srclang="en" label="English" default></video>
Embeds with iframe
An <iframe> embeds another page inside yours — YouTube, Google Maps, a form widget. Add title for accessibility and loading="lazy" for performance:
<iframesrc="https://www.youtube.com/embed/VIDEO_ID"title="Course intro video"width="560" height="315"loading="lazy"allowfullscreen></iframe>
Practice
Add a captioned <video> with a poster and two source formats, an <audio> player, and a lazy-loaded YouTube <iframe> with a proper title. Confirm the caption track toggles in the player.
Key takeaways
- 01<video>/<audio> play natively with controls; multiple <source> tags provide format fallbacks.
- 02autoplay requires muted; poster sets the preview frame.
- 03Add <track kind="captions"> (WebVTT) — always caption instructional video.
- 04<iframe> embeds external pages (YouTube, maps); add title and loading="lazy".
- 05Only embed trusted sources; use the sandbox attribute to restrict untrusted iframes.
