How to Embed a YouTube Video Responsively (Autoplay, Loop, Privacy)

How YouTube iframe embeds work, how to make them resize on phones, and what autoplay, loop, start time and privacy-enhanced mode really do in 2025.

Updated September 29, 2026 5 min read

Use the free YouTube Embed Code GeneratorBuild responsive YouTube iframe code with start, autoplay, loop and more

Embedding a YouTube video looks trivial: copy the code from the Share menu and paste it into your page. Then the problems start. The video is a fixed 560 pixels wide and overflows on phones. Autoplay does nothing. Loop plays once and stops. The privacy team asks whether the embed sets cookies before anyone presses play.

This guide explains what the standard embed code does, how to make it responsive, what each common player option really controls, and how to generate clean code for your site. YouTube's player parameters are documented in its IFrame Player API reference; they occasionally change, so check that reference for anything critical.

What an embed actually is

A YouTube embed is an <iframe>: a window on your page that loads a separate page from YouTube. The basic shape is:

<iframe width="560" height="315"
  src="https://www.youtube.com/embed/VIDEO_ID"
  title="YouTube video player"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
  allowfullscreen></iframe>

Everything about playback is controlled by parameters added to the src URL, such as ?start=30&mute=1. The allow attribute grants the iframe permission to use browser features like autoplay and fullscreen.

Making it responsive

The fixed width and height are the main reason embeds break on mobile. The modern fix uses CSS aspect-ratio, which is supported in all current browsers:

<div style="position:relative;width:100%;aspect-ratio:16/9;">
  <iframe style="position:absolute;inset:0;width:100%;height:100%;"
    src="https://www.youtube-nocookie.com/embed/VIDEO_ID"
    title="Product demo" loading="lazy"
    allowfullscreen></iframe>
</div>

The wrapper takes the full width of its container and keeps a 16:9 shape; the iframe fills it. Older tutorials use a padding-top: 56.25% trick for the same effect, which still works.

What the common options do

Option Parameter What it really does
Start / end time start=30, end=90 Plays a segment, in seconds
Autoplay autoplay=1 Only works reliably when muted, because browsers block autoplay with sound
Mute mute=1 Starts silent; viewers can unmute
Loop loop=1 plus playlist=VIDEO_ID A single video only loops if it is also set as its own playlist
Hide controls controls=0 Removes the control bar
Captions on cc_load_policy=1 Shows captions by default where available
Related videos rel=0 Since 2018 this no longer hides related videos; it limits them to your own channel
Privacy-enhanced mode youtube-nocookie.com domain YouTube says it does not store viewer information until the viewer plays the video

Two of these trip people up often. Autoplay is controlled by browsers, not YouTube: sound-on autoplay is blocked in most cases, so muting is required. Loop needs the extra playlist parameter for a single video.

For privacy-enhanced mode, read your own legal guidance: it reduces tracking before playback, but once a visitor presses play they are interacting with YouTube. Some sites add a click-to-load placeholder so nothing from YouTube loads until consent.

Generate code with our tool

The YouTube Embed Code Generator builds the iframe code in your browser. The optional preview loads YouTube's player only when you ask for it.

  1. Open the YouTube Embed Code Generator.
  2. Paste a link into YouTube video or playlist URL. Playlist links are detected and embedded as playlists.
  3. Enter a Title attribute (for accessibility) that describes the video; screen readers announce it.
  4. Optionally set Start at and End at.
  5. Keep Responsive (fills its container at 16:9) on, or turn it off and set Width and Height.
  6. Choose options: Privacy-enhanced mode, Autoplay (which adds mute automatically), Start muted, Show player controls, Loop, Show captions by default, Related videos from same channel only and Lazy-load iframe.
  7. Click Copy code. Use Load preview to test it with the real player.

Other ways to embed

YouTube's Share, then Embed. Gives you correct basic code with an optional start time and a privacy toggle. It is not responsive by default and offers few options.

Your CMS. WordPress, Squarespace, Wix and most site builders turn a pasted YouTube URL into a responsive embed automatically. If yours does, that is usually the simplest route; use custom code only when you need specific parameters.

Other iframes. For embedding maps, forms or other pages, the general iframe generator builds similar code.

Tips and troubleshooting

Autoplay still does not work

Check that mute=1 is present and allow includes autoplay. Even then, some browsers and data-saver settings block autoplay entirely. Design the page so it works without it.

"Video unavailable" in the embed

The owner may have disabled embedding, or the video is restricted in some regions. Test the embed link directly in a browser tab.

The page loads slowly

Each YouTube iframe loads a lot of script. loading="lazy" defers off-screen embeds. For pages with many videos, a thumbnail image that swaps to the player on click is lighter still.

Starting at a specific moment

The start value is in seconds. The YouTube Timestamp Link Generator converts mm:ss for you and also produces share links.

Titles and escaping

If your title attribute contains quotes or ampersands, they must be escaped as HTML entities. The generator does this; for hand-written code, the HTML Entity Encoder helps.

Frequently asked questions

How do I make a YouTube embed responsive?

Wrap the iframe in a container with width:100% and aspect-ratio:16/9, and make the iframe fill that container. The generator's Responsive option produces this code.

Why does YouTube autoplay not work in my embed?

Browsers block autoplay with sound. Add mute=1 along with autoplay=1, and make sure the iframe's allow attribute includes autoplay.

How do I loop a single YouTube video?

Add loop=1 and also playlist=VIDEO_ID with the same video ID. Without the playlist parameter, a single video will not loop.

Not fully. Since 2018, rel=0 limits related videos to your own channel rather than removing them.

What is YouTube's privacy-enhanced mode?

It serves the embed from youtube-nocookie.com. YouTube states it does not store information about visitors until they play the video.

Try it now: YouTube Embed Code Generator

Loading tool…