HTML Video Tag: Attributes, Supported Formats, and Examples
What is HTML Video Tag: Attributes, Supported Formats, and Examples? The HTML5 element embeds video streams directly into web pages without third-party plugins. By configuring attributes like 'controls', 'poster', 'autoplay', 'm...
How do you embed and customize video playback using the HTML5 <video> tag?
Explanation & In-Depth Details
2) Standard Video Formats:
- MP4 (H.264/AAC): Universal compatibility across iOS, Android, macOS, Windows, and Linux.
- WebM (VP9/AV1): Open, royalty-free container optimized for modern web streaming.
- OGG (Theora/Vorbis): Legacy open container.
3) Critical Attributes:
- controls: Displays native browser controls (play, pause, volume, full screen, timeline).
- poster="url.jpg": Displays a thumbnail poster image while the video downloads or before playback begins.
- autoplay: Starts playback immediately (requires 'muted' attribute on mobile and modern browsers).
- muted: Mutes audio output by default.
- playsinline: Prevents mobile browsers (like iOS Safari) from forcing full-screen mode on playback.
- loop: Causes the video to replay continuously in a loop.
4) Adding Subtitles and Captions (<track>): The <track> child element embeds timed WebVTT (.vtt) text tracks for closed captions, subtitles, chapter markers, and audio descriptions, ensuring WCAG accessibility compliance.
5) Responsive Video Sizing: By applying CSS 'max-width: 100%; height: auto;', videos seamlessly adjust their dimensions to fit mobile and tablet screens.
Code Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Video Player Demo</title>
</head>
<body>
<h2>Responsive HTML5 Video with Subtitles</h2>
<video controls poster="https://via.placeholder.com/640x360" width="640" height="360" style="max-width: 100%; height: auto; border-radius: 8px;" preload="metadata">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
<source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
<!-- Subtitles Track for Accessibility -->
<track src="/subtitles/captions_en.vtt" kind="subtitles" srclang="en" label="English">
Your browser does not support native HTML5 video.
</video>
</body>
</html>Interview Question & Tips
A1: Without 'playsinline', iOS Safari automatically expands all video playback into an aggressive full-screen modal, breaking inline backgrounds and custom UI designs.
Q2: How do you embed a silent background looping video?
A2: Add 'autoplay loop muted playsinline' attributes to the <video> tag. Muted is mandatory for modern browsers to allow autoplay without user interaction.
Q3: What is the purpose of the <track> element?
A3: The <track> element links WebVTT text files to provide closed captions and subtitles, enabling deaf or hard-of-hearing users to comprehend the video and meeting WCAG Level AA standards.
Best Practices
This study reference for HTML Video Tag: Attributes, Supported Formats, and Examples is curated and verified against recognized curriculum benchmarks, peer-reviewed textbooks, and official technical documentation: