Embedding Videos
Updated Mar 30, 2019 ·
Overview
You can embed videos in an HTML page using the <video>
tag. This allows you to play video files directly on the webpage without needing external players.
<video width="640" height="360" controls>
<source src="video.mp4" type="video/mp4">
</video>
src
points to the video filecontrols
adds playback controls like play, pause, and volumewidth
andheight
set the display size of the video
<video>
vs. <iframe>
Using <video>
Using a <video>
:
<video class="video-background"
autoplay
loop
muted
playsinline
poster="https://abc.xyz/~/media/store/banner/banner.jpg?rev=12345678">
<source src="https://player.vimeo.com/progressive_redirect/file.mp4?loc=external&signature=876945321"
type="video/mp4">
</video>
Using <iframe>
You can also use <iframe>
if you want adaptive streaming or less hassle:
<iframe
src="https://player.vimeo.com/video/VIDEO_ID?autoplay=1&loop=1&background=1&muted=1"
frameborder="0"
allow="autoplay; fullscreen"
allowfullscreen>
</iframe>
What autoplay=1&loop=1&background=1&muted=1
does:
- Removes title, controls, logo, everything
- Enables looping and autoplay
- Makes the video behave like a background video
Comparison
Feature | <video> Tag | <iframe> Embed |
---|---|---|
Raw video file (e.g. .mp4) | ✅ Yes | ❌ No |
YouTube video support | ❌ Not supported | ✅ Required |
Full control with HTML5 | ✅ Total control | ⚠️ Limited (YouTube API needed for more control) |
Autoplay & Loop (YouTube) |