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.
  • controls displays the play, pause, and volume controls.
  • src specifies the location of the audio file.
  • type tells the browser what kind of audio file it is.
Remember: The file path must point to an actual audio file. Writing music.mp3 won't magically create a song!

Other useful audio attributes

<audio controls loop>
  <source src="music.mp3" type="audio/mpeg">
</audio>
  • loop repeats the audio when it finishes.
  • autoplay requests automatic playback, but browsers may block it.
  • muted starts 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?

  • controls displays the video controls.
  • width sets the video's width.
  • height can set the video's height.
  • poster displays an image before the video plays.
  • loop repeats the video.
  • muted starts 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

  • src points to the caption file.
  • kind describes the type of text track.
  • srclang identifies the language.
  • label gives the track a readable name.
  • default marks the track as the default option.
Extra: WebVTT caption files usually use the .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.

Important: Some websites block iframe embedding. Always use the embed code provided by the service when available.

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:

  1. A heading called "My Media Page".
  2. An audio player with controls.
  3. A video player with controls.
  4. A poster image for your video.
  5. An embedded external video or webpage.
  6. 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?

⚙