HTML Multimedia

Beginner
14 min read
Updated: Nov 2026
6 examples
audio / video

Definition and Usage

HTML multimedia is how you put sound and video into a page using native tags—mainly <audio> and <video>—instead of plugins.

What is the shared media model?

Both elements share the same media engine in the browser (HTMLMediaElement). Attributes such as controls, muted, loop, and preload, plus script methods like play() and pause(), work the same way on audio and video.

What belongs on an HTML page?

Put the media element in your markup, point it at a file with src or nested <source> tags, and give users a way to play (controls or custom buttons). Use <track> for captions, and <iframe> when the video is hosted elsewhere (YouTube, Vimeo).

When should you use native media vs embeds?

Host your own files with audio / video when you need full control of formats, posters, and captions. Use an iframe when a platform already hosts and streams the clip.

Always offer controls.

Native controls (or an accessible custom UI) let visitors play, pause, and change volume. Autoplay with sound is usually blocked.

Muted autoplay only.

If you need background motion, use autoplay muted playsinline. Never assume loud autoplay will start.

Tag pages vs this hub.

Deep attribute lists live on audio and video. This page shows how multimedia fits together on an HTML page.

HTML Syntax

Minimal patterns for audio, video, captions, and a page-script control:

HTML
<audio controls>
  <source src="sound.mp3" type="audio/mpeg">
  Your browser does not support audio.
</audio>
HTML
<video width="640" height="360" controls poster="thumb.jpg">
  <source src="clip.webm" type="video/webm">
  <source src="clip.mp4" type="video/mp4">
  <track kind="subtitles" src="en.vtt" srclang="en" label="English">
  Your browser does not support video.
</video>
JS
var media = document.getElementById("demo");
media.play();   // returns a Promise
media.pause();
media.currentTime = 0;
media.muted = true;

Core HTML Concepts

Building blocks of multimedia on a page:

Element / ideaRole on the page
<audio>Sound-only media
<video>Moving picture (+ optional sound)
<source>Alternate formats; browser picks the first it can play
<track>Subtitles / captions (WebVTT)
<iframe>Hosted players (YouTube, Vimeo, …)
HTMLMediaElementShared API behind audio and video

Shared media attributes

AttributeMeaning
controlsShow the browser’s play / seek / volume UI
srcSingle media URL (or use nested source)
mutedStart silent (needed for many autoplay cases)
loopReplay when the clip ends
autoplayTry to start automatically (often blocked with sound)
preloadnone | metadata | auto
posterImage shown before video plays (video only)

Useful media methods & state

APIUse from a page script
play() / pause()Start or stop playback (play() returns a Promise)
currentTimeRead or seek position (seconds)
durationLength in seconds (after metadata loads)
muted / volumeSilence or set loudness (0–1)
paused / endedRead-only playback state
Eventsplay, pause, ended, timeupdate, error, …

How to Add Multimedia to an HTML Page

A simple workflow from markup to playback:

  1. Choose audio or video (or an iframe for hosted video).
  2. Provide one or more source files with correct type MIME values.
  3. Add controls (or build accessible custom buttons that call play() / pause()).
  4. For video, set width / height or CSS size; optional poster.
  5. Add track for captions when the clip has speech.
  6. Write fallback text between the tags for older browsers.
GoalHTML pattern
Playable sound<audio controls><source …></audio>
Playable video<video controls><source …></video>
Silent hero loop<video autoplay muted loop playsinline>
Captions<track kind="subtitles" src="en.vtt" …>
YouTube / Vimeo<iframe src="…/embed/…" title="…" allowfullscreen>

Live Preview

Native video with browser controls. Optional buttons call the shared media methods from a page script.

Status updates as media events fire on the element.

Status
Ready — use controls or the buttons above.

HTML Examples

Six patterns: audio, audio attributes, video, poster, YouTube iframe, and a full page.

Example 1 — Basic Audio

HTML
<audio controls>
  <source src="t-rex-roar.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
Try It Yourself

How It Works

  1. controls turns on the shared media UI.
  2. source points at an MP3 with the right MIME type.
  3. Fallback text shows if the browser cannot play audio.
  4. Same pattern works for video with a different tag name.

Example 2 — Audio with loop and preload

HTML
<audio controls loop preload="metadata">
  <source src="t-rex-roar.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>
Try It Yourself

How It Works

  1. loop restarts when playback reaches the end.
  2. preload="metadata" loads duration without downloading the whole file.
  3. controls still lets the user stop the loop.
  4. These attributes map to the shared media element model.

Example 3 — Basic Video

HTML
<video width="640" height="360" controls>
  <source src="flower.webm" type="video/webm">
  <source src="flower.mp4" type="video/mp4">
  Your browser does not support the video tag.
</video>
Try It Yourself

How It Works

  1. Two sources cover WebM and MP4.
  2. The browser uses the first format it understands.
  3. width / height reserve layout space before the first frame.
  4. controls expose play, seek, and volume on the page.

Example 4 — Video with Poster

HTML
<video width="640" height="360" controls poster="thumbnail.jpg">
  <source src="flower.webm" type="video/webm">
  Your browser does not support the video tag.
</video>
Try It Yourself

How It Works

  1. poster shows an image until the user presses play.
  2. Useful for branding and avoiding a black empty box.
  3. Video-only attribute (audio has no poster).
  4. Still pair with controls so playback is clear.

Example 5 — YouTube Embed

HTML
<iframe width="560" height="315"
  src="https://www.youtube.com/embed/EngW7tLk6R8"
  title="HTML tutorial video"
  allowfullscreen></iframe>
Try It Yourself

How It Works

  1. iframe loads a hosted player—not your own media file.
  2. title describes the embed for accessibility.
  3. allowfullscreen lets users expand the player.
  4. Swap the URL with any Share → Embed link.

Example 6 — Complete Multimedia Page

Combines audio, video, and an embedded iframe:

HTML
<!DOCTYPE html>
<html lang="en">
<head>
  <title>HTML Multimedia Example</title>
</head>
<body>
  <h1>HTML Multimedia Example</h1>

  <h2>Audio Example</h2>
  <audio controls>
    <source src="audio.mp3" type="audio/mpeg">
  </audio>

  <h2>Video Example</h2>
  <video width="640" height="360" controls>
    <source src="video.webm" type="video/webm">
  </video>

  <h2>Embedded Video</h2>
  <iframe src="https://www.youtube.com/embed/VIDEO_ID"
    title="Tutorial video" allowfullscreen></iframe>
</body>
</html>
Try It Yourself

How It Works

  1. One HTML document can mix native media and embeds.
  2. Headings label each media block for structure.
  3. Native tags use your files; iframe uses a host.
  4. Try It opens the full editable page.

Edge Cases & Pitfalls

Most media bugs are autoplay policy, missing formats, or inaccessible players.

autoplay

Sound blocked on autoplay

Use muted for decorative video, or wait for a user gesture before play().

format

Only one file format

Offer at least MP4 (video) / MP3 (audio) plus a modern alternative when you can.

a11y

No captions for speech

Add a track WebVTT file for spoken content; describe iframe embeds with title.

layout

Layout jump when video loads

Set dimensions or aspect-ratio CSS, and consider a poster.

cors

Cross-origin media limits

Some script features need proper CORS headers on the media host.

promise

Ignoring play() rejection

play() returns a Promise—catch failures so your UI can fall back to a Play button.

Browser Support

Native audio and video (HTMLMediaElement) are Baseline and available in all modern browsers. Always provide fallback text and multiple sources when formats differ.

✓ Baseline · Widely available

Native HTML media

audio, video, source, and track work across current browsers without plugins.

100% audio / video
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
HTML media elements Universal

Bottom line: Use controls, offer solid formats, and treat autoplay with muted as the safe default for decorative video.

Key Takeaways

  • audio and video are the native HTML way to embed media.
  • Shared attributes (controls, muted, loop) come from the media element model.
  • source + track cover formats and captions; iframe covers hosted players.
  • Prefer user control over loud autoplay.

One line: Put media in HTML with audio/video (or iframe), give users controls, and use the shared media API only when you need custom play/pause.

Frequently Asked Questions

HTML multimedia means putting sound and video into a web page with native tags—mainly audio and video—plus helpers like source, track, and iframe for hosted players. No Flash or plugins are required in modern browsers.
HTMLMediaElement is the shared browser interface behind both audio and video. Attributes like controls, muted, and loop, plus methods like play() and pause(), come from that shared media model.
Use audio for sound only. Use video when you need a picture (with optional sound). Both share the same media attributes and can use multiple source children for formats.
Browsers often block autoplay with sound. Prefer muted autoplay for decorative video, or let the user press play with controls. Never depend on autoplay always working.
Put a track element inside video with kind="subtitles" (or captions), srclang, label, and a WebVTT (.vtt) file. Users can enable tracks from the browser controls.
Use an iframe with the embed URL from Share → Embed. Add a descriptive title and allowfullscreen. Hosted iframes are separate from native audio/video files on your server.

Practice in the editor

Open the full multimedia page and tweak audio, video, and iframe embeds.

Open Try It editor →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful