HTML
๐ฌ HTML Multimedia
๐น 1. What is HTML Media / Multimedia?
Modern web pages are not limited to just text and images.
They can also include audio, video, animations, and other interactive media.
๐ All these types of content are called multimedia.
With HTML5, new elements were introduced that allow browsers to directly handle media files without extra plugins.
The most important ones are:
-
<video>โ for videos -
<audio>โ for sound
๐น 2. Supported Formats & Compatibility
Not every browser supports every media format, so developers usually provide multiple formats for better compatibility.
๐ Common formats:
- Video:
- MP4 (most widely supported)
- WebM
- Ogg
- Audio:
- MP3 (most common)
- WAV
- Ogg
๐ File extensions like .mp4, .mp3, .wav usually indicate the format.
๐น 3. <video> and <audio> Tags
๐๏ธ Video Example
HTML
<video width="320" height="240" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.webm" type="video/webm">
Your browser does not support the video tag.
</video >
๐ Key points:
- controls adds play, pause, volume, and timeline controls
- Multiple
<source>elements allow fallback formats - If none are supported, the text inside
<video>is shown
๐น 4. Advanced Usage Examples
๐ฅ Example A: Auto-Play & Loop Video
HTML
<video width="400" height="225" autoplay loop muted>
<source src="sample.mp4" type="video/mp4">
<source src="sample.webm" type="video/webm">
Your browser does not support the video tag.
</video >
๐
- autoplay โ starts automatically
- loop โ repeats continuously
- muted โ starts without sound (required for autoplay in most browsers)
๐๏ธ Example B: Controlling Video with JavaScript
HTML
<video id="myVid" width="320" height="180">
<source src="clip.mp4" type="video/mp4">
<source src="clip.webm" type="video/webm">
</video>
<button id="btnPlay">Play / Pause</button>
<p id="status">Stopped</p>
<script>
const video = document.getElementById("myVid");
const btn = document.getElementById("btnPlay");
const status = document.getElementById("status");
btn.addEventListener("click", () => {
if (video.paused) {
video.play();
status.innerText = "Playing";
} else {
video.pause();
status.innerText = "Paused";
}
});
</script>
๐
- play() and pause() control playback
- You can update UI elements like status text
- Enables custom controls (buttons, sliders, etc.)
๐ฌ Example C: Background Video
HTML
<video autoplay loop muted playsinline id="bgvid"
style="position: fixed; right: 0; bottom: 0; min-width: 100%; min-height: 100%;">
<source src="background.mp4" type="video/mp4">
<source src="background.webm" type="video/webm">
</video>
<div style="position: relative; z-index: 1;">
<h1>Page Title</h1>
<p>Text content goes here.</p>
</div>
๐
- position: fixed โ keeps video in the background
- min-width / min-height โ covers the full screen
- z-index โ ensures text appears above the video
- playsinline โ prevents fullscreen on mobile
Summary
- HTML5 allows embedding media directly using
<video>and<audio> - No external plugins are required
- Multiple formats ensure browser compatibility
- JavaScript enables full control over playback
Common uses:
- Video players ๐ฅ
- Music/audio playback ๐ต
- Background media ๐ฌ
- Interactive experiences ๐ฎ
- ๐ Multimedia is a key part of modern web design and user experience.
