MODULE 02 · SEMANTIC & STRUCTURAL HTML

Embedding Audio, Video & iFrames

Bring sound, video, and other websites directly into your page — with the built-in browser controls that make them work without a single line of JavaScript.

Day 12 of 30 Beginner ~20 min

Three Tags, Three Kinds of Media

So far you've embedded static images with <img>. HTML5 also gives you native tags for playable media and embedded pages: <audio>, <video>, and <iframe> — each with its own job.

The <audio> Tag

The controls attribute is what makes the play button, timeline, and volume slider appear — without it, the audio is invisible and silent.

snippet.html
<audio controls>
  <source src="lesson-intro.mp3" type="audio/mpeg">
  Your browser doesn't support the audio element.
</audio>
CONCEPT PREVIEW
1:12 / 3:20

Using <source> instead of a plain src attribute lets you offer more than one file format, so the browser picks whichever one it supports.

The <video> Tag

<video> works almost identically to <audio>, with a few extra attributes for sizing and behavior.

snippet.html
<video controls width="640" poster="thumbnail.jpg">
  <source src="day12-demo.mp4" type="video/mp4">
  Your browser doesn't support the video element.
</video>
CONCEPT PREVIEW
640 × 360 video frame
ATTRIBUTE WHAT IT DOES
controls

Shows the built-in play, pause, and volume interface.

poster

Sets a preview image shown before the video starts playing.

autoplay

Starts playback automatically — use sparingly, and always with muted.

loop

Restarts the video automatically once it reaches the end.

The <iframe> Tag

An <iframe> ("inline frame") embeds an entire separate web page inside a small window on your own page — commonly used for YouTube videos, Google Maps, and embedded forms.

snippet.html
<iframe
  src="https://www.youtube.com/embed/dQw4w9WgXcQ"
  width="560"
  height="315"
  title="Lesson recap video"
  allowfullscreen>
</iframe>
CONCEPT PREVIEW
560 × 315 embedded page (e.g. a YouTube player)
ALWAYS INCLUDE A TITLE

The title attribute on an <iframe> isn't just a tooltip — screen readers rely on it to describe what the embedded content actually is, so never skip it.

Breaking Down What You Just Learned

1

<audio controls>Embeds a playable sound file with built-in playback controls.

2

<video controls>Embeds a playable video file, optionally with a poster thumbnail.

3

<source>Offers one or more file formats inside <audio> or <video> for browser compatibility.

4

<iframe>Embeds a separate web page inside your own, sized with width and height.

5

title on <iframe>A required accessibility label describing what's embedded.

Try It Yourself

EXERCISE

Embed any public YouTube video on a test page using <iframe>, giving it a descriptive title and a fixed width and height.

Build a Mini Media Page

HANDS-ON EXERCISE

Combining audio, video, and an iframe on one page

Create a new file called day12.html inside your course folder and build a simple media showcase.

  1. Start with the full DOCTYPE, html, head, and body structure.
  2. Add a <video> element with controls and a poster image, using a placeholder file path.
  3. Add an <audio> element with controls, using a placeholder mp3 file path.
  4. Add an <iframe> embedding a public YouTube video, with a proper title attribute.
  5. Give each media element a heading above it describing what it is.
  6. Confirm every <iframe> has a title and every <audio>/<video> has the controls attribute.

Recap

AUDIO

Embeds a sound file with native browser playback controls.

VIDEO

Embeds a video file, with poster, loop, and autoplay options.

SOURCE

Provides multiple file formats for browser compatibility.

IFRAME

Embeds an entire external web page, sized and titled.

Key Takeaways

  • <audio> and <video> embed playable media with native browser controls.
  • The controls attribute is what makes playback buttons visible at all.
  • <source> lets you offer multiple formats for wider browser support.
  • <iframe> embeds a separate web page, like a YouTube video or a map.
  • Always give an <iframe> a descriptive title for accessibility.
Course Overview