YTNiches

YouTube Embed Code Generator

YouTube's default embed code gives you a fixed-size, non-responsive iFrame with no easy way to set autoplay, loop, or start time. This YouTube embed code generator creates responsive, customizable iFrame code — autoplay, loop, privacy-enhanced mode, Shorts support — no signup. Most guides also get the rel=0 parameter wrong. This one doesn't.

Options

How to Use This YouTube Embed Code Generator

Getting your embed code takes under 30 seconds.

Step 1 — Paste Your YouTube Video URL

Copy from the browser address bar or Share → Copy Link. Accepts: youtube.com/watch?v=, youtu.be/, youtube.com/playlist?list=, youtube.com/shorts/. Does NOT work with private videos or videos with embedding disabled.

Step 2 — Customize the Player Options

  • Autoplay — starts video automatically (must be muted)
  • Mute — required for autoplay to function
  • Loop — replays endlessly when finished
  • Controls — show or hide player controls
  • Start/End time — set exact seconds
  • Responsive — scales to any screen width
  • Privacy-enhanced mode — uses youtube-nocookie.com (GDPR)

Step 3 — Copy and Paste

Click “Copy Code” and paste into your website's HTML editor — WordPress Custom HTML block, Squarespace Code Block, Wix HTML Element, or raw HTML file. Never paste into a visual editor's text area.

YouTube Embed Code Parameters Explained

YouTube's iFrame embed accepts over 20 parameters. Here are the ones that actually matter — with current, accurate behavior.

📋 Reference: All parameters documented at developers.google.com/youtube/player_parameters

autoplay — Does It Actually Work?

Autoplay with sound is blocked by all major browsers unless the user has previously interacted with the site. The only reliable way: autoplay=1&mute=1 — muted autoplay works across all browsers.

<iframe src="https://www.youtube.com/embed/VIDEO_ID?autoplay=1&mute=1"
  allow="autoplay; encrypted-media" allowfullscreen>
</iframe>

rel=0 — What It Actually Does Now

⚠️ Most articles say rel=0 removes related videos entirely. This has not been true since September 2018.

Before 2018: rel=0 prevented ANY related videos at the end. Since September 2018: rel=0 shows related videos from the same channel only — not from other channels. There is no parameter that completely removes the related videos endscreen. Any guide saying otherwise is outdated.

loop, controls, mute, modestbranding

loop=1: Requires adding playlist=VIDEO_ID with the same ID — without this, loop does nothing on single videos.

?loop=1&playlist=VIDEO_ID

controls=0: Hides player controls. mute=1: Starts muted, required for autoplay. modestbranding=1: Reduces YouTube branding (effect limited since 2023, may be deprecated).

start & end — Custom Time Range

<!-- Embed from 1:30 to 3:00 -->
<iframe src="https://www.youtube.com/embed/VIDEO_ID?start=90&end=180"
  allowfullscreen>
</iframe>

Privacy-Enhanced Mode (GDPR Compliance)

Using youtube-nocookie.com prevents YouTube from tracking viewers with cookies until they click play — important for GDPR compliance.

<!-- Privacy-enhanced: no cookies until play -->
<iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID">
</iframe>

Complete Parameter Reference

ParameterValuesDefaultWhat It Does
autoplay0, 10Auto-starts video. Must use with mute=1
mute0, 10Starts muted. Required for autoplay
loop0, 10Loops video. Requires playlist=VIDEO_ID
controls0, 11Shows/hides player controls
rel0, 110 = same-channel related only (NOT zero related)
startinteger0Start time in seconds
endintegerEnd time in seconds
fs0, 11Enables/disables fullscreen button
cc_load_policy1Forces captions on by default
playsinline0, 10iOS: 1 = plays inline, 0 = fullscreen

How to Make Your YouTube Embed Responsive

YouTube's default embed outputs fixed 560×315 pixels. On mobile, this overflows or appears tiny. Two methods to fix it:

Method 1 — CSS Wrapper (Works Everywhere)

CSS:

.video-wrapper {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 */
  height: 0;
  overflow: hidden;
}
.video-wrapper iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}

HTML:

<div class="video-wrapper">
  <iframe src="https://www.youtube.com/embed/VIDEO_ID"
    frameborder="0" allowfullscreen>
  </iframe>
</div>

Method 2 — Modern CSS aspect-ratio

iframe {
  width: 100%;
  aspect-ratio: 16 / 9;
  height: auto;
}

Cleaner, no wrapper needed. Not supported in IE11 — fine for all modern browsers in 2026.

How to Embed YouTube Playlists and Shorts

Embedding a YouTube Playlist

<iframe src="https://www.youtube.com/embed/videoseries?list=PLAYLIST_ID"
  allowfullscreen>
</iframe>

Find your Playlist ID in the URL after list=. The embed starts at the first video with a playlist navigation panel.

Embedding YouTube Shorts — Vertical 9:16

Shorts are 9:16 vertical. Standard 16:9 wrappers show heavy black bars. Use a vertical wrapper instead:

.shorts-wrapper {
  position: relative;
  padding-bottom: 177.78%; /* 9:16 ratio */
  height: 0;
  overflow: hidden;
  max-width: 315px;
}
.shorts-wrapper iframe {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
}
<div class="shorts-wrapper">
  <iframe src="https://www.youtube.com/embed/SHORTS_VIDEO_ID"
    allowfullscreen>
  </iframe>
</div>

Use max-width: 315px to prevent Shorts from stretching too wide on desktop.

How to Embed YouTube Videos on Different Platforms

WordPress

Use Custom HTML block — NOT the YouTube embed block. Gutenberg: + → Custom HTML → paste code. Classic Editor: switch to Text tab. The YouTube block doesn't support custom parameters.

Squarespace

Add Block → Code Block (not Embed Block). Paste iFrame code → Apply.

Wix

Add Elements → Embed & Social → Embed HTML. Note: Wix sandboxes HTML — autoplay may not work reliably.

Webflow

Add Embed element → double-click → paste code → Save. Use parent div for responsive sizing.

HTML / Static Sites

Paste directly into your HTML file. Apply responsive CSS via your stylesheet.

Does Embedding YouTube Videos Help SEO?

Yes — with one significant caveat most guides ignore.

Time on Page and Engagement

Visitors watching embedded videos spend more time on your page — a positive engagement signal. For YouTube creators, embedding your own videos on your website also increases view count and watch time within YouTube.

Core Web Vitals — The Hidden Cost

A single YouTube iFrame loads 11–19 additional HTTP requests, adding 500KB–1MB to page weight before anyone plays anything. If above the fold, it becomes the LCP element — slowing your score significantly.

Solution — Facade / Lazy Loading: Render a static thumbnail instead of the full iFrame. Load the iFrame only when the visitor clicks play. See lite-youtube-embed for the best implementation.

Lazy Loading with loading="lazy"

<iframe src="https://www.youtube.com/embed/VIDEO_ID"
  loading="lazy" allowfullscreen>
</iframe>

Defers iFrame until near viewport. Simpler than facade pattern but less effective — still loads full iFrame on scroll.

YouTube Embed Code Troubleshooting

Black Screen or Error

Video is private, embedding disabled by creator, or browser extension blocking content. Test in incognito.

Autoplay Not Working

Add mute=1 alongside autoplay=1. Also add allow="autoplay; encrypted-media" to the iFrame tag.

“Video Unavailable”

Creator disabled embedding. No workaround exists.

Breaks on Mobile

Fixed width/height attributes. Apply responsive CSS wrapper. Add playsinline=1 for iOS inline playback.

Frequently Asked Questions

How do I get the embed code for a YouTube video?

Paste the URL into the generator above for custom code. Or on YouTube: Share → Embed for basic default code. Or build manually: youtube.com/embed/VIDEO_ID with parameters as query strings.

How do I make a YouTube embed responsive?

Wrap the iFrame in a div with position: relative; padding-bottom: 56.25%; height: 0. Set iFrame to position: absolute; width: 100%; height: 100%. Or use CSS aspect-ratio: 16 / 9 with width: 100%.

How do I embed without showing related videos?

Add rel=0 to your embed URL. Since September 2018, this shows related videos from the same channel only — not zero related videos. Complete removal of related videos is no longer possible.

Can I autoplay a YouTube video on my website?

Yes, but only muted. Use autoplay=1&mute=1 and add allow="autoplay; encrypted-media" to the iFrame tag. All browsers block autoplay with sound.

How do I embed a YouTube playlist?

Use: youtube.com/embed/videoseries?list=PLAYLIST_ID. Find the Playlist ID after “list=” in the playlist URL.

Why is my YouTube embed not working?

Common causes: video is private or embedding disabled, autoplay blocked (add mute=1), browser extension blocking iFrame, or fixed dimensions breaking on mobile.

How do I embed in WordPress?

Use Custom HTML block — NOT the YouTube embed block. The YouTube block doesn't support custom parameters. In Classic Editor, switch to the Text tab.

Does embedding help SEO?

Yes — increases time on page. But standard iFrames hurt Core Web Vitals (500KB–1MB page weight). Use lazy loading or facade pattern for performance-critical pages.

How do I embed YouTube Shorts?

Use youtube.com/embed/VIDEO_ID with the Shorts video ID. Shorts are 9:16 vertical — use padding-bottom: 177.78% and max-width: 315px on the wrapper.

YouTube's default embed code is a starting point — not a finished solution. This YouTube embed code generator handles responsive sizing, custom parameters, and privacy-enhanced mode automatically. The two things most guides get wrong: autoplay requires mute=1 to work in modern browsers, and rel=0 hasn't removed all related videos since 2018 — it shows same-channel videos only.