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 / Set the Page Title, Description, Language, and Encoding

HTML Tutorial / Set the Page Title, Description, Language, and Encoding

Build a complete HTML document with title, meta description, language, UTF-8 encoding, and viewport settings, then check their effects.

HTML Tutorial / Syntax

HTML Tutorial / Syntax

Learn the essential rules of HTML syntax, including elements, tags, attributes, void elements, comments, nesting, and the structure of a complete HTML document.

HTML Tutorial / Images: img, Alt Text, and Dimensions

HTML Tutorial / Images: img, Alt Text, and Dimensions

Add an image with HTML img, write useful alternative text, and set width and height correctly. A downloadable example helps you test file paths and sizing.

HTML Tutorial / Table Basics: table, tr, th, and td

HTML Tutorial / Table Basics: table, tr, th, and td

Build a basic HTML data table with rows and header or data cells, then organize its headings and body without using tables for page layout.

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 / Text Semantics: Emphasis, Quotations, Abbreviations, and Code

HTML Tutorial / Text Semantics: Emphasis, Quotations, Abbreviations, and Code

Learn when to use HTML em, strong, q, blockquote, abbr, code, and kbd. Examples show how each element conveys meaning rather than just changing the appearance of text.

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 / 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 / Add Placeholder Text to Form Fields

HTML Tutorial / Add Placeholder Text to Form Fields

Learn how to add placeholder hints to HTML input and textarea fields without confusing them with labels or initial values. Includes a complete form example, required-field checks, and an explanation of empty values in submitted data.

HTML Tutorial / Connect Labels and Inputs Correctly

HTML Tutorial / Connect Labels and Inputs Correctly

Connect labels to inputs with for and id, distinguish id from submitted name, and learn why placeholder text cannot replace a label.