YouTube Embed Code Generator
Paste a YouTube URL or video ID and generate a customizable iframe embed. Live preview as you toggle autoplay, loop, controls, start/end times, dimensions, and privacy mode. Copy a single-line, ready-to-paste embed code.
Works with watch URLs, <code>youtu.be</code> short links, <code>/shorts/</code> URLs, or just an 11-character video ID.
Paste a URL
Paste a watch URL, /shorts/ link, youtu.be short link, or just the 11-character video ID. We extract the ID and load the live preview.
Customize playback
Toggle autoplay, loop, and controls. Set start/end times in seconds or MM:SS. Pick width × height with a 16:9 lock. Choose privacy mode.
Copy & paste
Click Copy to grab the single-line iframe. Paste into HTML, Markdown, a CMS, or a rich-text editor. The player loads on first paint.
Paste any YouTube watch URL, youtu.be link, /shorts/ URL, or 11-character video ID and this tool builds a customizable <iframe> embed code. Toggle autoplay, loop, and controls, set start/end times, choose width × height (16:9 lock available), and pick privacy mode (youtube-nocookie.com) or standard. Live preview, copy-ready code, no upload, no signup.
What is a YouTube embed code generator?
A YouTube embed code is a small <iframe> snippet that loads YouTube's player on your own page. The browser fetches the player from YouTube, plays the video inside the frame, and pipes user controls back through YouTube's IFrame Player API. The frame's src URL — https://www.youtube.com/embed/{videoId} — is the only piece YouTube actually reads. Everything else (autoplay, loop, controls, start/end) is appended as query-string parameters that the player checks on load.
This generator builds that snippet for you. Paste a watch URL, youtu.be short link, /shorts/ link, or a bare 11-character ID; flip toggles for the playback options you want; and copy the result. The output is a single iframe — no JavaScript, no third-party loader, nothing to install. Paste it into HTML, Markdown, a CMS rich-text field, a Notion page, a Substack post, or wherever embeds are accepted, and the player loads on first paint.
Why customize an embed?
Defaults work fine when an embed is the focus of the page, but they're rarely right for hero videos, course platforms, kiosks, or marketing sites where the video is supporting content. Autoplay + mute + loop is the standard recipe for a background hero. Start time jumps past intros so a citation lands on the right moment. Hidden controls let the embed feel native rather than like a YouTube widget. Privacy mode defers cookie writes until the user actively plays, which simplifies consent flows under GDPR and ePrivacy rules. Most of these options aren't exposed by YouTube's share-dialog copy, which is why a separate generator is useful.
Embed privacy: what cookies a YouTube iframe drops
A YouTube embed is a network call to Google. Even before the user clicks play, the standard youtube.com/embed/{id} iframe loads JavaScript and image assets from googlevideo.com and sets a few session cookies — VISITOR_INFO1_LIVE, YSC, and a couple of analytics cookies. The privacy-enhanced host (youtube-nocookie.com) defers all of those until the user actually starts playback. For consent banners that block trackers by default, this is the difference between an embed that loads on first paint and an embed that needs a click-through. We default to nocookie because most pages benefit from it; switch to youtube.com only when you specifically need standard YouTube behavior.
Why does autoplay only work when muted?
Browsers block auto-playing audio by default. Chrome, Safari, Firefox, and Edge all enforce a media engagement policy: a video may auto-play only if it's muted, or if the user has previously interacted with the site at a meaningful level. The practical consequence for embeds is that autoplay=1 works reliably only when paired with mute=1. If you uncheck mute while autoplay is on, this tool surfaces a warning and the live preview will autoplay silently in some browsers and not at all in others — which is exactly what real visitors will experience. The fix is one of two things: keep mute on, or drop autoplay and let the user press play themselves. There's no third option.
youtube-nocookie.com vs youtube.com
Both hosts serve the same player and the same video. The difference is in cookie behavior. youtube.com sets a small set of session and analytics cookies on first frame load — even if the user never clicks play. youtube-nocookie.com defers cookie writes until the user explicitly starts playback. For a page that mostly shows the player but where most visitors don't watch, the nocookie host is the right default — fewer cookies dropped per visitor, simpler consent flows under GDPR / ePrivacy, and identical behavior when a user actually plays the video. There's no quality difference, no playback feature you lose, and no SEO penalty for using either host. This tool defaults to nocookie for that reason.
Deprecated parameters and what replaces them
A few embed parameters you'll see in older snippets are dead. showinfo=0 and rel=0 were retired in 2018 — the player ignores both. cc_load_policy=1 still works for forcing captions on, but YouTube also reads the viewer's account preference, so it isn't a guarantee. The enablejsapi=1 flag isn't deprecated, but it's only useful if you're calling the IFrame Player API from JavaScript on the host page; for a static embed it's noise. We omit all of these from the generated snippet by default — fewer bytes, fewer surprises, and nothing the player will ignore.
What this generator does not include
We deliberately omit a handful of options that shipped on older embed generators. The deprecated showinfo, rel, and stand-alone color tweaks (color=red/white) are out — the player no longer reads them. The fs=0 flag for hiding the fullscreen button is rarely useful on real sites, so it's not exposed; you can edit it into the generated code by hand if you need it. enablejsapi=1 only matters when you're scripting the player from your own page, which is a separate workflow from a static embed and out of scope here. Captions are available through cc_load_policy, but they default to the viewer's account preference — adding a checkbox here would mislead users into thinking it's a guaranteed switch, so we leave it off.
Embed parameters at a glance
These are the parameters the IFrame Player API actually reads. Anything not listed here is ignored or deprecated.
| Parameter | What it does | When to use it | Default |
|---|---|---|---|
autoplay | Starts the video automatically as soon as the iframe loads. | Background loops, hero videos, demo reels — always paired with mute, otherwise the browser blocks it. | 0 (off) |
mute | Starts the video with audio muted; the user can unmute via the player controls. | Always when autoplay is on. Sometimes useful on its own to make a hover-to-play affordance feel less intrusive. | 0 (off) |
loop | Replays the video from the start when it ends. Requires the <code>playlist</code> parameter for single-video loops. | Hero videos, animated backgrounds, kiosk displays where the video plays in a tight cycle. | 0 (off) |
controls | Shows or hides the player chrome (play/pause, progress bar, volume, settings). | Hide for autoplay loops or art-piece embeds where the UI competes with the page design. | 1 (visible) |
start | Starts playback at the given second offset, instead of from the beginning. | Linking to a specific moment — quoting a talk, citing a tutorial step, jumping past an intro. | — |
end | Stops playback at the given second offset from the start of the video. | Embedding a single segment from a longer talk or stream — pair with <code>start</code> to clip both sides. | — |
| host | Switches the iframe host between <code>youtube.com</code> and <code>youtube-nocookie.com</code>. Same player, different cookie timing. | Privacy-conscious sites, GDPR consent flows, pages where most visitors never click play. | youtube-nocookie.com |
Each row maps to one URL parameter on the iframe <code>src</code>. Parameters set to their default value are omitted from the generated code so the snippet stays small.
Common Uses
- Blog posts and articles: embed a video at a specific timestamp using the start parameter to skip intros and land readers on the cited moment.
- Marketing pages and landing sites: use a muted, autoplaying, looping background hero video to set tone without the audio competing with copy.
- Documentation and tutorials: embed a clipped segment with start and end times set, so each step links to its own video region.
- Privacy-first websites: use the youtube-nocookie host so embeds load without setting tracking cookies until the user actively presses play.
- Kiosks and digital signage: turn off controls and loop a single video for a clean, minimal display surface.
- Course platforms and LMS embeds: drop a sized iframe into a lesson page where you can't run third-party scripts but plain HTML is allowed.
How this compares to YouTube's official embed code
YouTube's own share dialog gives you an embed code, but it's a one-shot copy: you get a fixed snippet with a hard-to-customize default size (560×315), a checkbox for start time, and a privacy-mode toggle. Anything else — toggling controls, looping a single video, setting an end time, picking a non-default size — has to be edited by hand or wired up through the IFrame Player API. The official code is also chattier (extra attributes, a slightly older allow list) than what the player actually requires.
This generator gives you all the parameters the player honors in one form, with a live preview that updates as you toggle. The output is the minimum surface that reflects your choices: defaults are omitted, deprecated parameters are skipped, and the iframe attributes match the modern allow spec. Single-line output goes straight to the clipboard so it pastes cleanly into JSX, Markdown, and CMSes that gag on multi-line attributes; the multi-line view is purely for human reading.
Related YouTube tools
- Download YouTube thumbnails — Grab a single video's thumbnails at every resolution from default to Max HD.
- Download YouTube Shorts thumbnails — Same as the thumbnail downloader, but tuned for /shorts/ URLs with the SHORTS badge.
- Compare YouTube thumbnails — Lay two videos' thumbnails side-by-side at every resolution. Useful for A/B research and competitor study.
FAQ
Will this work for private or unlisted videos?
Unlisted videos work — anyone with the link, including the iframe's src, can watch. Private videos do not embed publicly; they require the viewer to be signed in to a Google account that's been added to the video's allowlist, and the iframe will show a 'video unavailable' message to anyone else. If you embed a private video and your visitors aren't on the allowlist, they will see nothing.
Why isn't there a download button on the player?
YouTube's terms of service prohibit downloading from embedded players, and the IFrame API doesn't expose a hook for it. The download UI inside the player itself is gated to YouTube Premium users on youtube.com — it never appears on third-party embeds. If you need to host a downloadable copy, upload the video to your own site or a service that supports direct file links.
How do I make the embed responsive on mobile?
The fixed-size iframe this tool generates is the YouTube standard, but it doesn't shrink on small screens. The common fix is to wrap the iframe in a container with position: relative; padding-bottom: 56.25%; height: 0; and style the iframe with position: absolute; top: 0; left: 0; width: 100%; height: 100%;. The 56.25% is 9 ÷ 16 — that's how you preserve the 16:9 ratio on any width. Drop the width and height attributes from the iframe when you do this.
Can I embed a specific timestamp without using the start parameter?
You can — append ?t=120 to a watch URL on YouTube and the page jumps to 2 minutes, but the iframe player ignores t. For embeds, the parameter is start (in seconds). This generator accepts 120, 2:00, or 0:02:00 in the Start at field and converts it for you. The end parameter works the same way.
What's the difference between privacy mode and an ad-free embed?
Privacy mode (youtube-nocookie.com) only changes when YouTube drops cookies — it waits until playback starts. It does not hide ads, and it does not stop YouTube from collecting data once the user clicks play. There is no embed flag that disables ads on a free account; YouTube Premium subscribers see ad-free playback on their own viewing, but the embed itself can't suppress ads for other viewers.
Why does the live preview always use youtube-nocookie regardless of the toggle?
So that browsing this page doesn't drop YouTube cookies on you when you didn't explicitly ask for it. The privacy toggle controls only the generated code — the snippet you'll copy. The preview iframe on this page is fixed to youtube-nocookie.com; the toggle's setting is what gets baked into the code you take with you.
Does the loop parameter work on a single video?
Yes, but with a quirk: loop=1 alone is silently ignored by the player. To loop a single video, you also need playlist={videoId} — the same video ID, repeated. This tool adds the playlist parameter automatically when you turn loop on, so the generated code loops cleanly without you having to remember the trick.
By the Numbers
- 200×113 minimum: below this size, YouTube's player hides its own controls and shows a smaller fallback. Above that, every dimension up to 4096px on a side renders cleanly. The default 560×315 is YouTube's own historic embed size; 16:9 holds at any pair that satisfies
height = width × 9 ÷ 16. - ~310 bytes per snippet: the generated single-line iframe is between roughly 280 and 360 bytes depending on options. By comparison, a standard YouTube share-dialog embed is closer to 420 bytes because it includes attributes (
referrerpolicy, fulltitle) that aren't strictly required. - 2 hosts, 7 parameters: two iframe hosts (
youtube.com,youtube-nocookie.com) and seven parameters that the player actually reads (autoplay,mute,loop,playlist,controls,start,end). Anything beyond that is either deprecated or only useful from the IFrame JavaScript API.