YouTube Embed Code Generator
Create responsive iframe embed codes with autoplay, loop, and other options.
Paste a YouTube URL to generate the embed code.
Embedding a YouTube video looks like copying the code YouTube gives you, and for a static page it is. The trouble starts on real websites: YouTube's default embed code is a fixed-size iframe that breaks responsive layouts, overflowing on phones and leaving gaps on wide screens. Getting a video to scale cleanly across every device requires a specific CSS technique that YouTube's copy button does not provide, plus knowing which of the many embed parameters actually do what they claim. This tool builds a responsive, correctly-parameterized embed code — autoplay, loop, start time, controls, and privacy mode — that behaves properly in a modern layout.
How the tool works
Paste a video URL and choose your options — autoplay, loop, muted start, hidden controls, a start time, privacy-enhanced mode. The tool generates the iframe code with those parameters set correctly, wrapped in the responsive container that makes it scale to any width while keeping the 16:9 aspect ratio. Copy the code into your page and the video resizes cleanly from phone to desktop without the overflow or letterboxing that raw embeds cause.
The responsive embed technique
Wrapper holds the aspect ratio; iframe fills it:
<div style="position:relative; padding-bottom:56.25%;
height:0; overflow:hidden;">
<iframe style="position:absolute; top:0; left:0;
width:100%; height:100%;"
src="youtube.com/embed/ID" ...></iframe>
</div>
56.25% = 9 ÷ 16 → locks 16:9 at any widthThe 56.25% padding is the whole trick. Padding-bottom expressed as a percentage is calculated against the element's width, so a padding of 9/16 forces the container to always be 56.25% as tall as it is wide — a perfect 16:9 box at any screen size. The absolutely-positioned iframe then fills that box. Modern CSS can do the same with aspect-ratio: 16/9, which is cleaner, but the padding technique still has the widest browser support, which is why generated embed code often uses it.
What to know about embedding
- 1Autoplay requires muted, by browser rule. Chrome, Safari, and Firefox all block autoplaying video with sound — a policy response to years of unwanted noise. An embed set to autoplay will only actually start if it is also muted; this tool pairs them so the autoplay you ask for actually works.
- 2Use privacy-enhanced mode unless you have a reason not to. Serving the embed from youtube-nocookie.com stops YouTube from setting tracking cookies until the viewer actually plays the video, which simplifies your cookie-consent obligations and is simply more respectful of visitors. It is a one-domain change with no downside for most sites.
- 3Every embed costs load performance. A YouTube iframe pulls in a substantial amount of script and resources, and several on one page noticeably slow it down. For pages with many videos, a 'facade' — a thumbnail image that loads the real iframe only on click — preserves speed while looking identical until interaction.
- 4Embeds count toward the creator's public view count, with conditions. A genuine play in an embedded player is a real view, which is why embedding your own videos on your site is legitimate promotion. Autoplaying muted loops generally do not count, since YouTube filters for intentional views — a reason not to expect a looping background video to inflate your numbers.
- 5Respect the aspect ratio of the actual content. The 16:9 responsive box is correct for standard videos, but Shorts are 9:16 vertical and need an inverted padding of 177.78%. Forcing vertical content into a horizontal box pillarboxes it with black bars — match the container to the source format.
Frequently asked questions
Why does my embedded video overflow on mobile?
Because YouTube's default embed code uses fixed pixel dimensions, like 560×315, which cannot shrink to fit a narrow screen. The fix is the responsive wrapper technique: a container that holds the 16:9 ratio using percentage padding, with the iframe absolutely positioned to fill it. That makes the video scale to any width automatically. This tool generates that wrapper for you rather than the fixed-size default.
Why won't my autoplay embed play automatically?
Browsers block autoplay with sound universally — it is a hard rule, not a setting you can override. An autoplaying embed only starts if it is also muted. This tool automatically adds the mute parameter when you enable autoplay, so the behavior you asked for actually happens. If you need sound, the viewer must start it, which is exactly the policy the browsers intend.
What is privacy-enhanced mode and should I use it?
It serves the embed from youtube-nocookie.com, which prevents YouTube from placing tracking cookies on visitors until they actually play the video. For most sites it is worth using: it eases cookie-consent requirements and respects visitors, with no functional downside — the video plays identically. The only reason to skip it is if you specifically rely on YouTube's standard tracking for the embed, which most sites do not.
Do embedded views count toward my video's view count?
Genuine plays do. When a visitor clicks play in an embedded player, that registers as a real view just as it would on YouTube itself, which is why embedding your videos on your own site is legitimate promotion. What does not count is autoplaying muted loops and other non-intentional plays — YouTube filters those out, so a silent background loop will not pad your numbers.
How do I embed a video that starts at a specific time?
Use the start parameter with a value in seconds — note that embeds require start, not the t used on watch links. This tool includes a start-time option that sets it correctly. If you also want the video to stop at a point, embeds uniquely accept an end parameter too, letting you play just a defined clip, which the normal watch page cannot do.