YouTube Embed Code Generator
Paste a video link, set your options, copy the iframe
What the YouTube embed code generator does
Paste a YouTube link into the tool above, tick the options you want, and copy the finished iframe. That is the whole routine. This YouTube embed code generator takes care of the fiddly parts: the right URL format, start and end times, a mute flag so autoplay works, and a wrapper that stops the video spilling off a phone screen.
What is a YouTube embed code?
A YouTube embed code is an iframe tag that points to youtube.com/embed/ followed by the video's ID. The ID is the 11-character string after v= in a normal watch URL. Paste the tag into a page and the YouTube player appears there. The video stays hosted on YouTube, so it costs you no storage and no video bandwidth.
Options go on the end of the src URL as parameters, for example ?start=30. Google lists every supported one in its YouTube embedded players and player parameters documentation, which also says the player needs a viewport of at least 200 by 200 pixels.
You can also copy a code straight from YouTube with Share, then Embed. That route gives you a fixed-size iframe and a few checkboxes, with no responsive wrapper and none of the playback options below. A generator fills that gap.
How to use the YouTube embed code generator
- Open the video on YouTube and copy its address from the browser bar.
- Paste it into the "Enter YouTube Video URL" box.
- Type a size if you need one. Leave it blank and you get the default 560x315.
- Fill in the start and end time fields (minutes and seconds) if you only want part of the video to play.
- Tick the options you want. They are explained in the next section.
- Click Generate and copy the code. Sample loads an example link, and Reset clears the form.
- Paste the code into the HTML of your page, where you want the video to appear.
What each option does
- Start and end time: adds
start=andend=in seconds, so 1:30 becomesstart=90. - Loop video: adds
loop=1&playlist=VIDEO_ID. Looping a single video needs the playlist value. - Auto play video: adds
autoplay=1&mute=1, because browsers block autoplay with sound. - Hide full-screen button: adds
fs=0. Viewers can no longer go full screen. - Hide player controls: adds
controls=0. Viewers lose the play bar and the volume slider. - Hide YouTube logo: adds
modestbranding=1, which no longer works. More on that below. - Privacy enhanced: switches the domain to
youtube-nocookie.com, so fewer cookies are set until someone presses play. - Responsive: wraps the iframe so it scales to the width of its container at a 16:9 ratio.
Make the embed responsive
The default 560x315 box does not shrink. On a 360-pixel phone it either overflows or forces the page to scroll sideways. The Responsive option fixes that by letting the iframe fill its container while keeping the 16:9 shape. If you would rather write it by hand, this does the same job:
<iframe
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
style="width:100%;aspect-ratio:16/9;border:0;"
allow="autoplay; encrypted-media; picture-in-picture"
allowfullscreen>
</iframe>
Use privacy-enhanced mode if your site has a cookie banner
With the Privacy enhanced box ticked, the code points to youtube-nocookie.com instead of youtube.com. YouTube then holds back its cookies until the visitor actually starts the video. It can make cookie compliance easier on sites with European traffic, but it does not replace consent where your local law asks for it.
<iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID" ...></iframe>
Autoplay and loop: the two that trip people up
Autoplay first. Browsers generally refuse to start a video that has sound, so the code needs mute=1 next to autoplay=1. Leave it out and the player just sits there waiting for a click.
Loop is stranger. On a single video, loop=1 does nothing unless playlist is set to that same video ID. The tail of the URL should look like this:
?autoplay=1&mute=1&loop=1&playlist=VIDEO_ID
Old tricks that no longer work
Search for how to hide the title in an embedded video and you will land on advice that is years out of date. showinfo=0 was retired in 2018, and the player ignores it, so the title stays. rel=0 used to remove related videos at the end. Now it only limits them to the same channel as the video that just played. And modestbranding=1, the parameter behind the Hide YouTube logo option, was deprecated in August 2023 and has no effect. Tick it if you like, but do not count on it to change what viewers see.
Where to paste the code
In WordPress, add a Custom HTML block and paste the iframe there. In Blogger, switch the post editor to HTML view. Most site builders have an HTML or embed block that does the same thing. Preview the page before you publish, especially on a phone.
Embeds and page speed
Every iframe loads YouTube's player scripts, and that adds weight to the page. For any video below the fold, add loading="lazy" to the iframe so it loads only when a visitor scrolls near it. The attribute is covered in MDN's iframe reference. Run the page through our Page Speed Checker before and after to see what the video costs you.
Check the video before you embed it
Some uploaders switch embedding off, and some videos are blocked in certain countries. Either way, your visitors get a grey box instead of a video. Run the link through the YouTube Region Restriction Checker first.
FAQ
How do I get the embed code for a YouTube video?
Paste the video link into the generator, choose your options, click Generate, and copy the result. On YouTube itself, use Share, then Embed, then Copy.
Can I embed a video that is not mine?
Yes, as long as the uploader allows embedding. If they have turned it off, the player shows an error instead of the video.
Why does my autoplay not start?
Browsers block autoplay when the video has sound. Add mute=1 to the URL and it will start.
Why does my embedded video not loop?
For a single video, loop=1 only works when playlist is set to the same video ID. Add &playlist=VIDEO_ID and try again.
Can I hide the video title in an embed?
No. The parameter that did it, showinfo, was retired in 2018.
Can I embed a whole playlist?
Yes. YouTube's playlist embed URL looks like https://www.youtube.com/embed?listType=playlist&list=PLAYLIST_ID. Swap in the ID from the playlist's address and use it as the iframe's src.
Is the generator free?
Yes. It is free and needs no registration.
Getting a video onto your page is half the work. Getting it found on YouTube is the other half. Our YouTube Tag Generator suggests tags for a new upload, and the YouTube Description Generator drafts the description.