Lesson 7: HTML Multimedia
HYPERLINK CODE ACADEMY • HTML COURSE
Lesson 07: HTML Multimedia
Learn how to add audio, video, and embedded content to your webpages.
01 — What Is HTML Multimedia?
Websites aren't limited to text, links, and images. You can also add audio, videos, animations, and other interactive media.
Think about websites like YouTube, Spotify, or news websites. They all use multimedia to make their content more interesting.
HTML provides several elements that allow you to display multimedia directly on a webpage.
<audio>— Plays audio files.<video>— Displays video files.<source>— Specifies a media file.<track>— Adds subtitles or captions to videos.<iframe>— Embeds another webpage or supported external content.
02 — Adding Audio
The <audio> element allows you to play sound files on your website.
Here's a basic example:
<audio controls>
<source src="music.mp3" type="audio/mpeg">
Your browser does not support audio.
</audio>
Understanding the code
<audio>creates the audio player.controlsdisplays the play, pause, and volume controls.srcspecifies the location of the audio file.typetells the browser what kind of audio file it is.
music.mp3 won't magically create a song!
Other useful audio attributes
<audio controls loop>
<source src="music.mp3" type="audio/mpeg">
</audio>
looprepeats the audio when it finishes.autoplayrequests automatic playback, but browsers may block it.mutedstarts the audio muted.
03 — Adding Video
The <video> element lets you display video files directly on your webpage.
<video controls width="500">
<source src="video.mp4" type="video/mp4">
Your browser does not support video.
</video>
What do the attributes do?
controlsdisplays the video controls.widthsets the video's width.heightcan set the video's height.posterdisplays an image before the video plays.looprepeats the video.mutedstarts the video without sound.
Adding a poster image
<video controls
width="500"
poster="thumbnail.jpg">
<source src="video.mp4" type="video/mp4">
</video>
The thumbnail appears before the visitor presses play.
04 — Adding Subtitles and Captions
Videos can include subtitles and captions using the <track> element.
This is useful for visitors who are deaf or hard of hearing, people watching without sound, and people who speak different languages.
<video controls width="500">
<source src="video.mp4" type="video/mp4">
<track
src="captions.vtt"
kind="captions"
srclang="en"
label="English"
default
>
</video>
Understanding the attributes
srcpoints to the caption file.kinddescribes the type of text track.srclangidentifies the language.labelgives the track a readable name.defaultmarks the track as the default option.
.vtt extension.
05 — Embedding External Content
Sometimes you don't want to upload a media file yourself. Instead, you might want to display content hosted on another website.
That's where the <iframe> element comes in.
An iframe can embed another webpage or content from services that allow embedding.
<iframe
src="https://example.com"
width="600"
height="400"
title="Example website"
></iframe>
Embedding a YouTube video
YouTube provides an embed option that gives you iframe code for videos that allow embedding.
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
allowfullscreen
></iframe>
Replace VIDEO_ID with the actual video's ID.
06 — Making Multimedia Responsive
What happens if a video is 900 pixels wide but someone visits your website on a phone?
It might overflow the screen!
CSS can help media adjust to different screen sizes.
video,
audio,
iframe {
max-width: 100%;
}
video {
height: auto;
}
This helps prevent media from becoming wider than its container.
For a more advanced responsive video layout, you can use a wrapper:
.video-container {
width: 100%;
aspect-ratio: 16 / 9;
}
.video-container iframe {
width: 100%;
height: 100%;
border: 0;
}
The aspect-ratio property helps preserve the shape of the video.
07 — Try It Yourself!
Your challenge is to create a small multimedia webpage.
Your page must include:
- A heading called "My Media Page".
- An audio player with controls.
- A video player with controls.
- A poster image for your video.
- An embedded external video or webpage.
- A short paragraph explaining what your page is about.
Start with this template:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Media Page</title>
</head>
<body>
<h1>My Media Page</h1>
<!-- Add your audio here -->
<!-- Add your video here -->
<!-- Embed external content here -->
</body>
</html>
Use media files that you own or have permission to use.
08 — Quick Knowledge Check
Question 1: Which HTML element plays audio files?
Question 2: Which attribute displays playback controls?
Question 3: Which element embeds another webpage?
Question 4: What does the poster attribute do in a video element?