AD JB Toolbox 01 EN

HTML Tutorial / Embed Audio, Video, and External Content

HTML can play media files with audio and video, or display another document inside a page with iframe. Successful embedding depends on real file paths and supported formats. Useful controls, captions or transcripts, and the trustworthiness of external content matter too.

Play audio and video files

The example assumes sample.mp3, sample.mp4, and sample-poster.webp are next to the HTML file. To run it, supply files you have the right to use and adjust the names as needed.

<audio controls>
  <source src="sample.mp3" type="audio/mpeg">
  Your browser does not support audio playback.
</audio>

<video controls width="640" height="360" poster="sample-poster.webp">
  <source src="sample.mp4" type="video/mp4">
  <track src="sample-en.vtt" kind="captions" srclang="en"
         label="English captions" default>
  Your browser does not support video playback.
</video>

controls provides the browser's playback controls, and poster is shown before a video plays. For speech or meaningful sounds, provide accurate captions. The referenced sample-en.vtt is not automatically created. Without that file, the captions cannot appear.

A WebVTT caption file is UTF-8 text. This minimal example shows one cue for the first three seconds; real captions must cover the video's speech and important sounds at the correct times.

WEBVTT

00:00:00.000 --> 00:00:03.000
Welcome to Small Garden.

When important information is conveyed by audio, also provide a text transcript. Let users start playback themselves rather than unexpectedly autoplaying sound. If you offer multiple source formats, the underlying files must actually use those formats; renaming an extension does not convert media.

Embed external content with iframe

An iframe displays another document within the current page. The URL below is a structural placeholder, not a working media embed. Replace it with an official embed URL supplied by the provider.

<iframe
  src="https://example.com/embed/example"
  title="Introduction to the example content"
  width="640" height="360"
  loading="lazy"></iframe>

The title describes the frame's purpose. A provider may forbid embedding even if its ordinary page URL works. External content can affect privacy, cookies, and performance, so use a trusted provider's official embed code only when it adds value. State the embedded item's title or context in nearby text so the surrounding article still makes sense when it does not load.

If media will not play or fit

  • Verify that the file exists at the specified path and the server sends the appropriate media type.
  • Check whether the browser supports the file's actual encoding, not only its filename extension.
  • Use CSS to limit the width on small screens without distorting the video's aspect ratio.
  • For external content, check the provider's embedding policy and terms.

See the MDN video reference and iframe reference for element-specific attributes.

More in This Category
HTML Tutorial / Links: Paths, Page Fragments, and Email

HTML Tutorial / Links: Paths, Page Fragments, and Email

Create HTML links with absolute or relative URLs, jump to a document fragment, and add email, new-tab, or download links. Learn what to verify before publishing.

HTML Tutorial / Find Errors and Validate an HTML Document

HTML Tutorial / Find Errors and Validate an HTML Document

Use the Nu HTML Checker to find markup errors, repair a duplicate ID, and supplement validation with browser and keyboard checks.

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

HTML Tutorial / Accessible Tables: caption, scope, and Spanning Cells

Make table headings and data relationships clear with caption, th, and scope, and learn when colspan or rowspan makes a table harder to read.

HTML Tutorial / When to Use div and span

HTML Tutorial / When to Use div and span

Understand the structural difference between div and span, style only the content you need, and choose semantic elements when they better describe the content.

HTML Tutorial / Use textarea, select, option, and button

HTML Tutorial / Use textarea, select, option, and button

Create multi-line fields, selection lists, and form buttons while understanding initial values, submitted values, and reset behavior.

HTML Tutorial / Basic Structure of an HTML Document

HTML Tutorial / Basic Structure of an HTML Document

Learn the roles of doctype, html, head, and body, then save your first HTML file and open it in a browser. Includes a complete example, a diagram, and fixes for common filename, refresh, and encoding problems.

HTML Tutorial / Explain Forms with fieldset, legend, and autocomplete

HTML Tutorial / Explain Forms with fieldset, legend, and autocomplete

Group related controls with fieldset and legend, and use suitable autocomplete tokens to describe the purpose of input fields.

HTML Tutorial / Lists: ul, ol, dl, and Nested Lists

HTML Tutorial / Lists: ul, ol, dl, and Nested Lists

Choose the right HTML list for ordered items, unordered items, and name–description pairs. Try a complete example, custom numbering, and correctly nested lists.

HTML Tutorial / Build a Small Multipage Website

HTML Tutorial / Build a Small Multipage Website

Create linked Home, About, and Contact pages, test a practice form, and check navigation, keyboard use, and HTML validity.

HTML Tutorial / Accessibility Basics: Headings, Links, Images, and Keyboard

HTML Tutorial / Accessibility Basics: Headings, Links, Images, and Keyboard

Review heading hierarchy, meaningful link text, image alternatives, and keyboard interaction as practical foundations of accessible HTML.