Audio, Video and Iframes
HTML can play sound and video by itself, with no extra player. Add controls to show play, pause and volume buttons.
Before HTML5, playing video on a website needed plug-ins like Flash. Now the browser plays audio and video itself, on phones and computers, with standard controls. You give it the file and a few settings, and it handles buffering, full screen and volume.
<video src="intro.mp4" width="480" controls poster="cover.jpg">
Sorry, your browser cannot play this video.
</video>
<audio src="song.mp3" controls></audio>Several formats
Not every browser plays every file type. Use <source> tags; the browser picks the first one it can play.
<video width="480" controls muted autoplay loop playsinline>
<source src="clip.webm" type="video/webm">
<source src="clip.mp4" type="video/mp4">
</video>autoplay- starts by itself. Browsers allow this only when the video is alsomuted.loop- plays again from the startplaysinline- plays inside the page on iPhones instead of going full screenposter- a picture shown before the video starts
Iframes: a page inside a page
An <iframe> shows another web page inside yours. YouTube and Google Maps give you iframe code to embed their videos and maps.
An iframe is a window into another website. It's the standard way to embed content you don't host yourself - a YouTube video, a Google Map with your shop's location, or a payment form. The embedded page runs separately from yours, which keeps both safe.
<iframe src="https://www.youtube.com/embed/VIDEO_ID"
width="560" height="315"
title="Product demo video"
loading="lazy"
allowfullscreen></iframe>title so screen-reader users know what it is, and use loading="lazy" so it loads only when the user scrolls near it.- <video> and <audio> play media; add controls.
- Offer several formats with <source>.
- Autoplay works only when muted.
- Iframes embed other pages; give them a title and loading="lazy".
