HTML provides native media elements—<audio> and <video>—so you can play sound and video without plugins. You add one or more <source> elements to offer different formats, and you can attach a <track> for captions or subtitles. Browsers pick the first source they support and render a built-in player if you include the controls attribute.
<audio controls> shows the browser’s audio player UI.<source> tags (e.g., MP3/OGG); the browser picks the first it supports.preload (none | metadata | auto), loop, muted, autoplay.<video controls> displays built-in controls for play/pause, timeline, etc.width/height or CSS for sizing, and poster for a thumbnail.autoplay muted playsinline (especially on mobile).<track kind="subtitles" srclang="en" label="English" default>.Basic structure of HTML audio and video elements with sources:
<!-- Audio with multiple sources -->
<audio controls preload="metadata">
<source src="sound.mp3" type="audio/mpeg">
<source src="sound.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
<!-- Video with poster, sources and subtitles -->
<video controls poster="poster.jpg">
<source src="movie.mp4" type="video/mp4">
<source src="movie.webm" type="video/webm">
<track src="subtitles.vtt" kind="subtitles" srclang="en" label="English" default>
Your browser does not support HTML video.
</video>
<!-- Audio with two sources and conservative preload -->
<audio controls preload="metadata">
<source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg">
<source src="https://www.w3schools.com/html/horse.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
<!-- Video with MP4/OGG sources, poster frame, and captions -->
<video controls width="480" poster="https://www.w3schools.com/html/pic_trulli.jpg">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
<source src="https://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg">
<track src="https://www.w3schools.com/tags/movie.vtt"
kind="subtitles" srclang="en" label="English" default>
Your browser does not support HTML video.
</video>
// Basic programmatic control
const vid = document.getElementById('v1');
vid.play(); // start
vid.pause(); // pause
vid.currentTime += 5; // skip forward
vid.volume = 0.5; // volume range: 0..1
// Toggle captions
const track = vid.textTracks[0];
track.mode = (track.mode === 'showing') ? 'disabled' : 'showing';
Use the buttons below to control the video player above with JavaScript.
Note: External demo media URLs may be rate-limited or blocked by some networks—replace with your own files as needed.
type attributes.autoplay with muted and playsinline to avoid blocks.preload="metadata" for lists; reserve auto for key media to save bandwidth.<track kind="subtitles"> for speech-heavy videos to improve accessibility.poster so the user doesn’t see a blank rectangle before play.<audio>/<video> elements.controls, be sure to implement a custom player UI with JavaScript.preload="auto" on many media items to prevent bandwidth drain.autoplay muted playsinline loop and test it on mobile..vtt captions file and connect it with a <track> element.preload values (none, metadata, auto) and inspect network usage.controls removed.src of a single <audio> element.<audio> and <video> provide native playback without plugins.<source> elements for different formats and add <track> for captions.controls, autoplay, muted, loop, and preload control behavior and performance.play(), pause(), currentTime, volume, etc.).