HTML5 introduced native media playback via <video> and <audio>, completely eliminating legacy Flash plugins. Modern media delivery requires cross-browser codec compatibility, responsive framing, and accessible closed captions.
The HTML5 <video> Element
<video
width="1280"
height="720"
controls
preload="metadata"
poster="/media/poster-frame.jpg"
playsinline
>
<!-- 1. Modern Open AV1 Codec -->
<source src="/media/conference.av1.mp4" type="video/mp4; codecs=av01.0.05M.08">
<!-- 2. VP9 in WebM Container -->
<source src="/media/conference.webm" type="video/webm; codecs=vp9">
<!-- 3. Universal H.264 Fallback -->
<source src="/media/conference.mp4" type="video/mp4">
<!-- Accessibility Closed Captions (WebVTT format) -->
<track
kind="captions"
src="/media/captions-en.vtt"
srclang="en"
label="English Captions"
default
>
<track
kind="subtitles"
src="/media/subtitles-es.vtt"
srclang="es"
label="Español"
>
<p>Your browser does not support HTML5 video. <a href="/media/conference.mp4">Download video</a>.</p>
</video>
Video Attributes Explained
playsinline: Essential for mobile Safari on iOS. Withoutplaysinline, video playback automatically hijacks the full screen, destroying custom UI overlays.poster: Displays an image placeholder before playback begins.preload:none: Does not buffer video bytes until the user clicks play (conserves mobile data).metadata: Fetches video duration and dimensions only (recommended default).auto: Buffers the video stream aggressively.
Closed Captions & The <track> Element
WCAG accessibility compliance mandates synchronized text captions for auditory content. The <track> element points to a WebVTT (.vtt) file:
WEBVTT
00:00:01.000 --> 00:00:04.500
Welcome to the CodeAcademix platform overview.
00:00:05.000 --> 00:00:09.200
In this masterclass, we explore modern HTML5 markup architecture.
Native Audio Streaming with <audio>
<audio controls preload="metadata">
<source src="/audio/podcast-ep42.opus" type="audio/ogg; codecs=opus">
<source src="/audio/podcast-ep42.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Secure & Sandboxed <iframe> Embeds
When embedding third-party content (such as YouTube videos or interactive code playgrounds), always harden the <iframe> with security attributes:
<iframe
src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ"
title="Educational Course Video Player"
width="560"
height="315"
loading="lazy"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
sandbox="allow-scripts allow-same-origin allow-presentation"
style="aspect-ratio: 16 / 9; width: 100%; height: auto; border: 0;"
></iframe>
title: Mandatory for accessibility so screen readers announce the frame contents.sandbox: Restricts what the embedded iframe can execute (e.g., preventing popups or form hijacking).
Exercises
- Create a WebVTT file with two timestamped cues and bind it to a native HTML5 video player.
- Implement a responsive 16:9 video container using modern CSS
aspect-ratio: 16 / 9with no layout shifts. - Compare the security posture of an iframe with and without the
sandboxattribute.