How to embed a YouTube video
Dan Counsell · Founder of Realmac SoftwareUpdated
We’ve made RapidWeaver, a website builder for Mac, since 2004. Each guide works with any tool, then shows how in RapidWeaver Elements.
Embedding a video means it plays on your page, while YouTube stores it and handles the streaming. It’s free and doesn’t use your hosting’s bandwidth.
How to embed a YouTube video
- Open the video on YouTube.
- Click Share, then Embed.
- Choose any options, such as a start time.
- Click Copy.
- Paste the code into your page’s HTML.
The code looks like this:
<iframe width="560" height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></iframe>
Make the video responsive
The default code has a fixed width, so it spills off phone screens. Replace the width and height with a bit of CSS:
<iframe src="https://www.youtube.com/embed/VIDEO_ID"
title="A short description of the video"
style="width: 100%; aspect-ratio: 16 / 9; border: 0;"
allowfullscreen></iframe>
Change the title to describe the video, so screen reader users know what it is.
Useful options
Add these to the end of the address, after a ?. Join more than one with &.
| Option | What it does |
|---|---|
start=90 |
Starts at 90 seconds |
rel=0 |
Shows related videos from the same channel only |
mute=1 |
Starts muted (needed for autoplay in most browsers) |
autoplay=1 |
Plays when the page loads |
loop=1&playlist=VIDEO_ID |
Loops the video |
Use privacy-enhanced mode
Change youtube.com to youtube-nocookie.com in the embed address. YouTube then doesn’t store cookies until the visitor plays the video.
To go further, show a thumbnail image and only load the player when someone clicks it. The page loads faster and nothing from YouTube loads until it’s wanted.
Embed a video in RapidWeaver Elements
RapidWeaver Elements has a Video component for YouTube, Vimeo and MP4 files, so there’s no code to paste.
- Drag the video’s YouTube address from your browser into Resources.
- Drag the Video component onto your page from the Media group.
- Pick your video under Video > Resource.
- Choose autoplay, controls, looping, start time and aspect ratio, or open it in a lightbox.
You can also use a video as a section background, from the background settings of a Container.
Questions about embedding YouTube videos
Why won’t my embedded video play?
The video owner may have turned off embedding, or the video is private. Unlisted videos can be embedded; private ones can’t.
Does embedding a YouTube video slow down my site?
A little, because the player loads extra files. Loading the player only when someone clicks keeps your page fast.
Can I embed someone else’s YouTube video?
Yes, if they’ve allowed embedding. The video still belongs to them and plays from their channel.