The YouTube embed code generator turns a video, Short, or playlist link into one <iframe> tag to paste into your page’s HTML. It runs in your browser, starts from the code YouTube’s Share → Embed dialog gives, and adds an end time, a responsive size, and a 9:16 frame for Shorts. Privacy-enhanced mode starts switched on.
How to get the embed code for a YouTube video
- Under the video on YouTube, select Share, then Copy. In the YouTube app, tap Share, then Copy link.
- Paste the link into the box above and select Get embed code.
- Pick a size and the options you want. The preview and the code follow your choices.
- Select Copy embed code, then paste it into your page’s HTML or your site editor’s HTML view.
YouTube also writes embed code itself. Under a video, select Share, then Embed for a fixed 560x315 player with Start at, Show player controls, and Enable privacy-enhanced mode. It has no end time or responsive size. In our tests, the Share menu on a Short had no Embed option at all.
As YouTube’s dialog says, embedding a video means agreeing to the YouTube API Services Terms of Service.
Links you can paste
- Watch links:
youtube.com/watch?v=…, includingm.youtube.comlinks copied on a phone. - Share links:
youtu.be/…, as YouTube’s Share button copies them. - Shorts and live videos:
youtube.com/shorts/…andyoutube.com/live/…. - Embed links:
youtube.com/embed/…andyoutube-nocookie.com/embed/…. - Playlists:
youtube.com/playlist?list=…. The embed plays the playlist from its first video. - A video in a playlist: a watch link with
list=in it. The embed keeps that video and plays the rest of the playlist after it. - A video ID: the 11 characters after
v=in a watch link.
A time in the link, such as t=90 or t=1m30s, fills in Start at. A link to a Mix, whose list ID starts with RD, embeds its video alone.
What each option does
Each option adds a player parameter or iframe attribute. All of them are on YouTube’s list except mute, which the player accepts though the list leaves it out. An option left at YouTube’s default adds nothing, so the code stays short.
| Option | Adds to the code | What it does |
|---|---|---|
| Start at | start=180 |
Starts the video 3 minutes in. |
| End at | end=420 |
Stops it at 7 minutes. |
| Privacy-enhanced mode | youtube-nocookie.com |
Loads YouTube’s privacy-enhanced player. On by default. |
| Same-channel suggestions | rel=0 |
Ends with suggestions from the video’s own channel. On by default. |
| Turn captions on | cc_load_policy=1 |
Shows captions when the video plays. |
| Hide player controls | controls=0 |
Hides the player’s controls. |
| Autoplay muted | autoplay=1&mute=1 |
Starts the video without sound. Autoplay is always muted here. |
| Lazy loading | loading="lazy" |
Waits to load the player until a reader scrolls near it. On by default. |
Every code also carries YouTube’s own allow list, allowfullscreen, and the referrer policy that keeps it playing. Its title attribute holds the video’s real title from YouTube’s oEmbed service, so screen readers announce it. The generator leaves out the si sharing parameter YouTube adds to its own code.
More options
Settings fewer embeds need sit under More options, each with its parameter in its note.
| Option | Adds to the code | What it does |
|---|---|---|
| Play inline on iPhone | playsinline=1 |
Plays the video in the page on an iPhone instead of fullscreen. On by default. |
| Hide fullscreen button | fs=0 |
Removes the fullscreen button. |
| Turn off keyboard shortcuts | disablekb=1 |
Stops keys like space and the arrows from controlling the player. |
| White progress bar | color=white |
Draws the progress bar in white instead of red. |
| Loop | loop=1 |
Starts the video or playlist again when it ends. |
| Caption language | cc_lang_pref=fr |
Opens captions in that language, with Turn captions on, when the video has them. |
| Player language | hl=fr |
Sets the language of the player’s menus and tooltips. |
| Then play | playlist=ID1,ID2 |
Plays these videos after the first one. |
| JavaScript API | enablejsapi=1 |
Lets your page’s scripts control the player through the IFrame API. |
| Your site, for the API | origin=… |
Names your site, which YouTube asks for whenever the API is on. |
| Page the widget sits on | widget_referrer=… |
Credits that page in the channel’s YouTube Analytics when the player is in a widget. |
YouTube’s own list says loop has limited support in embeds, and a single video loops as a playlist of itself, so the code adds playlist with the video’s own ID.
Responsive or fixed size
Responsive, the default, makes the player fill the width of the space you paste it into and keeps it at 16:9. The code stays a single <iframe> with a CSS aspect-ratio style, so there’s no wrapper <div> to lose when an editor tidies your HTML. Its width and height stay in the code for editors that strip styles.
Fixed sets the width and height in pixels, 560x315 by default. YouTube’s player needs at least 200x200 pixels, and YouTube recommends 480x270 or larger for a 16:9 player.
How to embed YouTube Shorts and playlists
A Shorts link gets a tall 9:16 player: 315x560 at a fixed size, or the full width of its space up to 315 pixels when responsive. In our tests, a Short in a wide 16:9 player sat between blurred bars. A Short’s Share menu has no Embed option, so paste its link here to get the code.
YouTube lets sites embed a whole playlist as well as a video. Paste the playlist’s link to play it from the top, or a watch link from inside the playlist to start at that video.
Why a YouTube embed won’t play
- Error 153. YouTube blocks embedded playback when the request carries no HTTP Referer, the header that tells YouTube which site the player is on. Its player rules require one, recommend the
strict-origin-when-cross-originpolicy, and don’t allownoreferrer. The code here sets that policy on the iframe. If the error persists, check that your editor kept thereferrerpolicyattribute. - The owner turned off embedding. Owners can stop other sites from embedding their videos, and the preview then says playback on other websites is disabled. Link to the video on YouTube instead.
- It’s age-restricted. Age-restricted videos can’t be watched on most other websites. Link to it on YouTube instead.
- It’s private. A private video can be seen only by its owner and the people they choose. The generator still writes the code and warns you that most visitors can’t play it.
Which YouTube embed options still work
Older tutorials list options YouTube has since changed. Its player parameters page records each change:
rel=0can’t hide suggested videos. Since 25 September 2018, it shows suggestions from the same channel, and no parameter turns them off.modestbrandinghas had no effect since 15 August 2023.showinfohas been ignored since 25 September 2018.
The generator offers none of these.
Start and end times still work, with two catches. The video may start up to about 2 seconds before your Start at, at the nearest keyframe. End at counts from the beginning of the video, even with a start time, so a clip from minute 3 to minute 7 is Start at 3:00 and End at 7:00.
Autoplaying a YouTube embed
Autoplay muted starts the video without sound. YouTube doesn’t count autoplayed embeds as views, so leave it off when the views matter to the channel. YouTube’s player rules also let a player autoplay only once more than half of it is visible, and allow one autoplaying player per page.
Privacy-enhanced mode and youtube-nocookie.com
Privacy-enhanced mode loads the player from youtube-nocookie.com. YouTube says views there don’t influence the viewer’s YouTube experience, and any ads are non-personalized. The player still connects to YouTube, and in our tests it stored data in the browser as soon as it loaded, so read what privacy-enhanced mode does before you rely on it for consent rules.
More tools for the videos you embed
To watch a video in the privacy-enhanced player before you embed it, open it in the cookie-free YouTube watcher. To save its thumbnail, use the YouTube thumbnail downloader, which explains when you need the creator’s permission to reuse it. To tell students how long a lecture takes at 1.5x or 2x, use the playback speed calculator. Retube, our free browser extension, groups your YouTube subscriptions into topic feeds such as Learning or Science, so the channels you embed from sit together inside YouTube.