YouTube Embed Code Generator
Paste a YouTube URL, customize the player, and copy the embed code. Autoplay, start time, privacy mode, responsive sizing.
How to Embed a YouTube Video on a Website
Add a YouTube video to any website in three steps. Works with any site builder, CMS, or custom code.
Paste the YouTube URL
Copy the video URL from YouTube's address bar, share button, or mobile app. We support all URL formats: watch?v=, youtu.be/, /shorts/, and /embed/.
Customize the player
Choose a size, toggle autoplay, set start/end times, enable privacy mode, and tweak the player controls. The live preview updates as you change settings.
Copy the embed code
Pick your format (HTML, WordPress, Markdown, or React) and copy the code. Paste it into your site's HTML editor, page builder, or component file.
YouTube Embed Parameters Reference
YouTube's IFrame Player API accepts URL parameters that control player behavior. Add them to the embed URL after the video ID:
| Parameter | Values | Description |
|---|---|---|
autoplay |
0 or 1 |
Auto-start the video on page load. Most browsers require mute=1 for this to work. |
mute |
0 or 1 |
Start the video muted. Required for autoplay to work in Chrome, Safari, and Firefox. |
controls |
0 or 1 |
Show or hide player controls (play, volume, progress bar, fullscreen). |
loop |
0 or 1 |
Loop the video. Requires playlist=VIDEO_ID to work for single videos. |
start |
Seconds | Start playback at this many seconds into the video. |
end |
Seconds | Stop playback at this many seconds. The video pauses (doesn't hide). |
rel |
0 or 1 |
When 0, related videos shown at the end are restricted to the same channel. You cannot fully disable related videos. |
fs |
0 or 1 |
Enable or disable the fullscreen button. Default is 1 (enabled). |
playlist |
Video ID | Required for looping a single video. Set to the same video ID. |
cc_load_policy |
1 |
Show closed captions by default (if available). |
Responsive YouTube Embed CSS
A fixed-width iframe breaks on mobile. The standard approach is a CSS wrapper that maintains the 16:9 aspect ratio while scaling to the container width. Here's the code:
CSS method (works everywhere)
.video-container {
position: relative;
width: 100%;
padding-bottom: 56.25%; /* 16:9 */
height: 0;
overflow: hidden;
}
.video-container iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
Modern CSS method (aspect-ratio)
.video-container {
width: 100%;
max-width: 800px;
}
.video-container iframe {
width: 100%;
aspect-ratio: 16 / 9;
border: 0;
}
Supported in all modern browsers. Simpler code, same result. Use max-width to cap the size.
Privacy-Enhanced Embedding with youtube-nocookie.com
YouTube's privacy-enhanced mode changes the embed domain from youtube.com to youtube-nocookie.com. Here's what that means:
What it does
- YouTube doesn't set tracking cookies on the visitor's browser until they click play
- Reduces your site's cookie footprint for GDPR/privacy compliance
- The embedded player looks and works identically
- All embed parameters (autoplay, start, loop, etc.) work the same way
What it doesn't do
- It doesn't block all tracking. Once the viewer clicks play, cookies are set
- It doesn't prevent YouTube from collecting view data on their end
- It's not a full GDPR solution on its own. You may still need a consent banner
- It doesn't affect video availability or quality
How to enable it: Toggle "Privacy-enhanced mode" in the tool above, or manually replace youtube.com with youtube-nocookie.com in your embed URL. That's the only change needed.
Frequently Asked Questions
How do I embed a YouTube video on my website?
Copy the YouTube video URL, paste it in the generator above, and copy the generated <iframe> code. Paste that code into your website's HTML where you want the video to appear.
If you're using WordPress, Squarespace, or another page builder, switch to the HTML/code editing mode before pasting the iframe code. Most page builders also let you paste a raw YouTube URL and auto-embed it, but you lose customization control.
Why isn't autoplay working?
Modern browsers (Chrome, Safari, Firefox, Edge) block autoplay with sound to prevent annoying experiences. Autoplay only works if the video is muted.
To make autoplay work reliably, enable both the "Autoplay" and "Muted" toggles. The generated code will include autoplay=1&mute=1 and the iframe allow="autoplay" attribute.
What is the default YouTube embed size?
YouTube's default embed size is 560 × 315 pixels (16:9 aspect ratio). This is what you get when you click "Share" → "Embed" on YouTube.
For modern websites, use a responsive embed instead of a fixed size. A responsive embed scales to fit the container width while maintaining the 16:9 aspect ratio, so it works at any screen width.
How do I make a YouTube embed responsive?
Select the "Responsive" size option in the generator above. The code wraps the iframe in a container with CSS that maintains the 16:9 aspect ratio at any width.
The classic technique uses padding-bottom: 56.25% on the container. Modern browsers also support aspect-ratio: 16/9 directly on the iframe, which is simpler.
Can I embed a YouTube Shorts video?
Yes. Paste the Shorts URL and the tool will convert it to a standard embed. Shorts are vertical (9:16), but the embed plays in a standard horizontal player. The video will have black bars on the sides (pillarboxing).
All embed parameters (autoplay, loop, start time, etc.) work with Shorts embeds the same way they work with regular videos.
Do I need to install anything?
Build YouTube Tools with an API
Need video metadata, thumbnail URLs, or content analysis at scale? BrightBean's API gives you structured YouTube data as JSON.