FreeToolsLand

YouTube Embed Code Generator

Build the iframe, see it working, copy it.

Free, no signup, no limits

Browsers only allow this when muted

Needs the video listed as its own playlist

Uses youtube-nocookie.com

Restricts them to this channel. Nothing can remove them entirely

Fills its container and keeps a 16:9 shape. Turn off for fixed pixels

Live preview

The preview is the real embed, so it behaves exactly as it will on your page.

Embed code

<iframe
  style="width:100%;aspect-ratio:16/9;border:0"
  src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ"
  title="YouTube video player"
  frameborder="0"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
  referrerpolicy="strict-origin-when-cross-origin"
  allowfullscreen
></iframe>

Why your YouTube embed does not work

An embed is one line of HTML, and yet most hand-written ones misbehave in the same three ways. None of them is your fault. All three are silent.

Autoplay does nothing unless the video is muted. Browsers stopped allowing sound-on autoplay years ago. Your embed loads, sits still, and reports no error anywhere. Switching autoplay on here adds mute with it.

Loop does nothing on a single video. YouTube loops playlists, not videos, so loop=1 on its own is ignored. The fix is to hand the player a playlist containing that one video, which is what this generator writes for you.

Related videos cannot be removed. They could once, and half the tutorials online still say so. Since 2018, rel=0 only restricts the suggestions to the same channel. That is worth setting, but nobody can give you an embed with no suggestions at all.

How to make a YouTube embed responsive

For years the way to size an embed was a wrapper div with padding-bottom: 56.25% and an absolutely positioned iframe. That is no longer necessary. The CSS aspect-ratio property does the same job in one line, is supported everywhere that matters, and leaves you with a single element instead of two.

The responsive option here uses it. Turn it off if you specifically need fixed pixel dimensions.

What youtube-nocookie privacy mode changes

Privacy mode swaps the player host for youtube-nocookie.com. It does not make the embed anonymous, but it delays tracking cookies until someone presses play, which is the more defensible default if you have visitors in the EU. It is on by default here for that reason.

Frequently asked questions

Something missing here?

If this tool almost does what you need, say what is missing. That is usually how the next version gets built.