Modern websites are not limited to text, images, and forms.
We also need:
HTML provides native elements for multimedia:
<audio>
<video>
<source>
<track>The major advantage is that modern browsers can play many media formats without requiring plugins.
HTML multimedia means embedding media directly into a webpage using HTML.
For example:
<video controls>
<source src="video.mp4" type="video/mp4">
</video>The browser can provide the playback interface.
Conceptually:
HTML
│
├── <audio>
│ ↓
│ Audio player
│
└── <video>
↓
Video player<audio>#The <audio> element is used to embed sound.
Basic example:
<audio controls>
<source
src="song.mp3"
type="audio/mpeg"
>
</audio>The browser can display controls similar to:
┌──────────────────────────────────────┐
│ ▶ ━━━━━━━●━━━━━━━━ 🔊 │
└──────────────────────────────────────┘controls Attribute#Without:
controlsthe browser normally doesn't provide its standard visible playback controls.
Example:
<audio
src="song.mp3"
controls
>
</audio>The user can typically:
depending on the browser.
<source>?#Instead of:
<audio src="song.mp3" controls></audio>you can use:
<audio controls>
<source
src="song.mp3"
type="audio/mpeg"
>
</audio>This becomes especially useful when you want to provide multiple formats.
Example:
<audio controls>
<source
src="song.mp3"
type="audio/mpeg"
>
<source
src="song.ogg"
type="audio/ogg"
>
Your browser does not support audio playback.
</audio>The browser can choose an appropriate supported source.
Conceptually:
AUDIO
│
┌────────┴────────┐
│ │
MP3 source OGG source
│ │
└────────┬────────┘
│
Browser
│
▼
PlaySome commonly encountered formats:
| Format | MIME type | Typical use |
|---|---|---|
| MP3 | audio/mpeg |
General audio |
| Ogg | audio/ogg |
Open media ecosystem |
| WAV | audio/wav |
High-quality/uncompressed audio |
| AAC | audio/aac |
Audio encoding |
| WebM | audio/webm |
Web media |
Browser support and codec support can vary, so production sites should test their target browsers.
<section>
<h2>Podcast</h2>
<p>
Listen to our latest episode.
</p>
<audio controls preload="metadata">
<source
src="/podcast/episode-01.mp3"
type="audio/mpeg"
>
<source
src="/podcast/episode-01.ogg"
type="audio/ogg"
>
Your browser does not support audio playback.
</audio>
</section>This is already a good semantic structure.
<video>#The <video> element embeds video content.
Basic example:
<video
controls
width="640"
>
<source
src="video.mp4"
type="video/mp4"
>
</video>The browser can provide:
┌──────────────────────────────────────┐
│ │
│ VIDEO │
│ │
│ │
├──────────────────────────────────────┤
│ ▶ ━━━━━●━━━━━━━━━━━━ 🔊 ⛶ │
└──────────────────────────────────────┘controls#Just like audio:
<video controls>provides browser playback controls.
Without it:
<video>the user may not have an obvious way to control playback unless you build controls with JavaScript.
<video controls>
<source
src="movie.mp4"
type="video/mp4"
>
<source
src="movie.webm"
type="video/webm"
>
Your browser does not support video playback.
</video>The browser evaluates the sources and uses a compatible one.
| Format | MIME type | Typical use |
|---|---|---|
| MP4 | video/mp4 |
Very common web video |
| WebM | video/webm |
Web-focused media |
| Ogg | video/ogg |
Open media ecosystem |
But remember:
A file extension alone does not tell the whole story.
Video compatibility depends on the container and codec.
For example, an MP4 file can contain different video/audio codecs.
poster#You can specify an image shown before video playback:
<video
controls
poster="/images/course-thumbnail.jpg"
>
<source
src="/videos/html-course.mp4"
type="video/mp4"
>
</video>Conceptually:
Before play:
┌──────────────────────────────────┐
│ │
│ COURSE THUMBNAIL │
│ │
│ ▶ │
│ │
└──────────────────────────────────┘This is especially useful for:
width and height#You can specify dimensions:
<video
controls
width="800"
height="450"
>However, dimensions in HTML should describe the intended media dimensions; CSS is generally responsible for responsive presentation.
Knowing the media dimensions ahead of time can help browsers allocate appropriate space and reduce layout movement.
For example:
<video
width="1280"
height="720"
controls
>represents a 16
video.The aspect ratio is:
1280 / 720 = 1.777...approximately:
16:9For responsive layouts, CSS is typically used.
Example:
<video
controls
width="1280"
height="720"
>
<source
src="/video.mp4"
type="video/mp4"
>
</video>Then CSS might use:
video {
max-width: 100%;
height: auto;
}The important separation is:
HTML
→ describes the media
CSS
→ controls responsive presentationautoplay#You can request automatic playback:
<video
autoplay
controls
>
<source src="video.mp4" type="video/mp4">
</video>However, browsers often restrict autoplay when media contains audio.
That's why this common pattern exists:
<video
autoplay
muted
loop
>
<source
src="background.mp4"
type="video/mp4"
>
</video>Muted autoplay is much more likely to be allowed.
muted Is Important With Autoplay#Suppose:
<video autoplay>tries to start with sound.
Browsers may block it to avoid unexpectedly playing audio.
But:
<video
autoplay
muted
>is much more suitable for things such as:
Still, autoplay behavior can depend on browser policies and user settings.
loop#loop makes the media repeat.
Example:
<video
autoplay
muted
loop
>
<source
src="background.mp4"
type="video/mp4"
>
</video>The flow becomes:
Play
↓
End
↓
Start again
↓
End
↓
Start again
↓
...A common website hero:
<section>
<video
autoplay
muted
loop
playsinline
poster="/images/hero.jpg"
>
<source
src="/videos/hero.mp4"
type="video/mp4"
>
</video>
<h1>
Build the Future
</h1>
</section>The playsinline attribute is particularly relevant on mobile browsers.
playsinline#<video playsinline>This requests that video play inline rather than being forced into a separate fullscreen-style playback experience on supported mobile browsers.
It is commonly used with:
autoplay muted loop playsinlinefor background or inline video experiences.
preload#preload provides a hint about how much media the browser should preload.
Values include:
none
metadata
autoExample:
<video
controls
preload="metadata"
>none#preload="none"Hint:
Don't preload media unnecessarily.
metadata#preload="metadata"Hint:
Load metadata such as duration/dimensions where appropriate.
auto#preload="auto"Hint:
The browser may preload more of the resource.
Important:
preloadis a hint, not an absolute command.
preload#For a video below the fold:
<video
controls
preload="metadata"
>may be reasonable.
For a large video that users may never watch:
<video
controls
preload="none"
>can reduce unnecessary network activity.
For a media experience where early loading is important:
preload="auto"may sometimes make sense.
Always consider performance.
preload#The same concept applies to audio:
<audio
controls
preload="metadata"
>or:
<audio
controls
preload="none"
><track>#One of the most important multimedia accessibility features is:
<track>It can provide:
Example:
<video controls>
<source
src="lecture.mp4"
type="video/mp4"
>
<track
src="captions-en.vtt"
kind="captions"
srclang="en"
label="English"
default
>
</video>.vtt File?#VTT means:
Web Video Text Tracks
A simple VTT file can look like:
WEBVTT
00:00.000 --> 00:03.000
Welcome to the HTML course.
00:03.000 --> 00:06.000
Today we will learn semantic HTML.The browser uses these time ranges to synchronize text with the video.
These terms are often confused.
Generally communicate spoken dialogue, often for viewers who may not understand the spoken language.
Can include:
For example:
[Door opens]
Welcome to the course.
[Background music]Captions are particularly important for accessibility.
kind="captions"#Example:
<track
src="captions.vtt"
kind="captions"
srclang="en"
label="English"
default
>This indicates the track provides captions.
kind="subtitles"#Example:
<track
src="subtitles-hi.vtt"
kind="subtitles"
srclang="hi"
label="Hindi"
>This can provide Hindi subtitles.
You could provide multiple languages:
<video controls>
<source
src="course.mp4"
type="video/mp4"
>
<track
src="en.vtt"
kind="subtitles"
srclang="en"
label="English"
default
>
<track
src="hi.vtt"
kind="subtitles"
srclang="hi"
label="Hindi"
>
</video>srclang#This specifies the language of the track.
Example:
srclang="en"English.
srclang="hi"Hindi.
srclang="fr"French.
label#label gives the user a readable name for the track.
Example:
label="English"or:
label="Hindi"The browser can use this when presenting track choices.
default#You can specify a default track:
defaultExample:
<track
src="english.vtt"
kind="captions"
srclang="en"
label="English"
default
>A professional video should consider:
Video
│
├── Captions
├── Subtitles where appropriate
├── Keyboard accessibility
├── Clear controls
├── Text alternatives where needed
└── Audio description where appropriateDon't assume:
"Video = accessible automatically."It isn't.
Audio-only content can be inaccessible to users who cannot hear it.
For important audio content, provide a text transcript.
Example:
<section>
<h2>Podcast Episode 1</h2>
<audio controls>
<source
src="episode-1.mp3"
type="audio/mpeg"
>
</audio>
<p>
<a href="/transcripts/episode-1">
Read the transcript
</a>
</p>
</section>This provides an alternative way to access the information.
For important educational videos:
<section>
<h2>HTML Tutorial</h2>
<video controls>
<source
src="/videos/html.mp4"
type="video/mp4"
>
<track
src="/captions/html-en.vtt"
kind="captions"
srclang="en"
label="English"
default
>
</video>
<p>
<a href="/transcripts/html">
Read the full transcript
</a>
</p>
</section>This is a strong accessibility pattern.
No.
This is an important distinction.
<img> is a void element:
<img src="image.jpg" alt="...">But:
<audio></audio>and:
<video></video>are not void elements.
They can contain:
<source>
<track>and fallback text.
Example:
<video controls>
<source
src="video.mp4"
type="video/mp4"
>
Your browser does not support HTML video.
</video>The text after the <source> can serve as fallback content when the video cannot be used.
Similarly:
<audio controls>
<source
src="podcast.mp3"
type="audio/mpeg"
>
Your browser does not support HTML audio.
</audio>src vs <source>#You can write:
<video
src="video.mp4"
controls
>
</video>or:
<video controls>
<source
src="video.mp4"
type="video/mp4"
>
</video>Use <source> when you need:
type on <source>#Example:
<source
src="video.mp4"
type="video/mp4"
>The type tells the browser what media type the source represents.
Another:
<source
src="video.webm"
type="video/webm"
>This can help the browser decide whether it can use a source.
When JavaScript is introduced, media elements expose events such as:
play
pause
ended
timeupdate
volumechange
loadedmetadata
canplay
waitingExample:
const video = document.querySelector("video");
video.addEventListener("play", () => {
console.log("Video started");
});Or:
video.addEventListener("ended", () => {
console.log("Video finished");
});We'll explore media APIs later.
currentTime#JavaScript can access the current playback position:
const video = document.querySelector("video");
console.log(video.currentTime);For example:
currentTime = 35.5means approximately 35.5 seconds into the media.
You can also set it:
video.currentTime = 60;which seeks to approximately 60 seconds.
duration#You can read the duration:
console.log(video.duration);For example:
245.7means approximately:
245.7 secondsor about:
4 minutes 5.7 secondsplay() and pause()#JavaScript can control playback.
const video = document.querySelector("video");
video.play();Pause:
video.pause();This enables custom media players.
HTML:
<video
id="course-video"
src="course.mp4"
>
</video>
<button id="play">
Play
</button>
<button id="pause">
Pause
</button>JavaScript:
const video = document.querySelector("#course-video");
document.querySelector("#play").addEventListener(
"click",
() => {
video.play();
}
);
document.querySelector("#pause").addEventListener(
"click",
() => {
video.pause();
}
);Now you're building your own controls.
Before building a custom player, remember that:
controlsalready provides a browser-native media interface.
Native controls have advantages:
Build custom controls only when your product actually requires them.
muted#JavaScript can also control whether media is muted:
video.muted = true;or:
video.muted = false;HTML:
<video
muted
controls
>volume#JavaScript:
video.volume = 0.5;means approximately:
50% volumeThe range is generally:
0 → silent
1 → maximumplaybackRate#You can change playback speed:
video.playbackRate = 1.5;Possible values:
0.5 → half speed
1.0 → normal
1.5 → 1.5×
2.0 → 2×This is useful for:
Video can be extremely expensive compared with HTML text.
Consider:
HTML page
→ relatively small
Image
→ potentially several MB
Video
→ potentially hundreds of MBTherefore:
Consider:
preload="metadata"or:
preload="none"when appropriate.
Unlike images, video doesn't use:
loading="lazy"as a standard equivalent in the same way.
Instead, performance strategies may include:
preload="none"preload="metadata"Suppose your source video is:
2 GBThat's a terrible resource for most webpage use cases.
You should consider:
Compression
Resolution
Bitrate
Codec
Container
Streaming strategyFor example:
4K source
↓
1080p web version
↓
720p web version
↓
Adaptive streaming if neededFor production applications, especially large video platforms, you generally don't want:
Browser
↓
One giant video file
↓
Application serverInstead, a media architecture may use:
User
↓
CDN / Media service
↓
Video segments
↓
BrowserFor large-scale video platforms, adaptive streaming technologies such as HLS or MPEG-DASH may be used.
That's beyond basic HTML, but it's important to understand the architecture.
iframe vs <video>#This is an important distinction.
If you have your own video file:
<video controls>
<source src="video.mp4">
</video>But if you're embedding a video hosted by another platform, you may use:
<iframe
src="..."
title="Video"
></iframe>For example, many video platforms provide an embed URL.
Conceptually:
Your video
↓
<video>
External platform
↓
<iframe>We'll study <iframe> and embedded content in Chapter 13.
<audio> vs <video>#<audio> |
<video> |
|---|---|
| Sound | Video + potentially audio |
| Podcast | Tutorials |
| Music | Movies |
| Voice recording | Product demos |
| Audiobooks | Courses |
controls |
controls |
<source> |
<source> |
<track> can be used |
<track> commonly used for captions |
<audio controls>
<source src="song.mp3" type="audio/mpeg">
</audio><video controls>
<source src="video.mp4" type="video/mp4">
</video><video
controls
poster="thumbnail.jpg"
><video autoplay muted><video loop><video playsinline><video preload="metadata"><track
src="captions.vtt"
kind="captions"
srclang="en"
label="English"
><section>
<h2>HTML Course — Chapter 12</h2>
<figure>
<video
controls
width="1280"
height="720"
preload="metadata"
poster="/images/html-course.jpg"
>
<source
src="/videos/html-chapter-12.mp4"
type="video/mp4"
>
<source
src="/videos/html-chapter-12.webm"
type="video/webm"
>
<track
src="/captions/chapter-12-en.vtt"
kind="captions"
srclang="en"
label="English"
default
>
Your browser does not support HTML video.
</video>
<figcaption>
Chapter 12 — HTML Multimedia
</figcaption>
</figure>
<p>
<a href="/transcripts/chapter-12">
Read the transcript
</a>
</p>
</section>This combines:
section
heading
figure
video
source
track
captions
poster
preload
figcaption
transcriptExcellent production-oriented structure.
Avoid:
<audio autoplay>unless there's a very specific user-friendly reason.
Unexpected sound is a poor user experience.
Don't assume:
autoplaywill always work.
For background video, a common pattern is:
autoplay muted loop playsinlineFor important video content:
<track kind="captions">should be considered.
Don't ship:
500 MBwhen a properly optimized media asset could be much smaller.
Provide useful fallback text:
Your browser does not support HTML video.If a critical piece of information can be expressed directly as HTML text, don't make video the only way to access it.
<audio> used for?#Embedding audio content into an HTML document.
<video> used for?#Embedding video content.
<source>?#To provide one or more media sources and specify their types.
controls do?#Requests the browser's native media controls.
poster do?#Specifies an image shown as the video's poster frame before playback.
Browsers commonly restrict autoplay, particularly when media is not muted.
playsinline?#It requests inline playback on supported mobile environments rather than forcing a separate fullscreen-style experience.
<track>?#It provides timed text tracks such as captions, subtitles, chapters, or other track data.
Web Video Text Tracks, commonly used for timed text files.
They improve accessibility and allow people who cannot hear the audio to access the video's spoken and relevant audio information.
preload="none" and preload="metadata"?#none hints that the browser should avoid preloading the media, while metadata allows loading metadata without necessarily loading the complete media resource.
<audio> and <video> void elements?#No.
They can contain <source>, <track>, and fallback content.
Create:
multimedia.htmlwith:
Multimedia Gallery
────────────────────────────────────
1. Podcast
[ ▶ Audio Player ]
Read Transcript
2. HTML Tutorial
┌──────────────────────────────┐
│ │
│ VIDEO │
│ │
└──────────────────────────────┘
[ ▶ Controls ]
Captions:
English
Hindi
3. Product Demo
┌──────────────────────────────┐
│ VIDEO │
└──────────────────────────────┘
Product demonstration
4. Background Hero
Autoplay
Muted
Loop
Inline
Poster imageTry to use:
<audio>
<video>
<source>
<track>
<figure>
<figcaption>and appropriate accessibility features.
The multimedia architecture is:
MEDIA
│
┌────────┴────────┐
│ │
AUDIO VIDEO
│ │
source source
│ │
│ track
│ │
└────────┬────────┘
│
Browser
│
Native playbackFor professional multimedia:
Video
│
├── Appropriate source
├── Poster
├── Controls
├── Captions
├── Responsive sizing
├── Performance strategy
└── Transcript when appropriateThe key principle is:
Multimedia isn't just about making media play; professional HTML also considers accessibility, compatibility, performance, and user control.
Next we'll learn how HTML can embed external content and other browsing contexts:
<iframe><embed><object><picture> vs embedded contentsandboxallowloadingreferrerpolicypostMessageMark it as complete to track your mastery.