Skip to content

Responsive YouTube Embed Code Generator

Paste a YouTube link and get embed code that scales to any screen and loads fast.

Aspect ratio

Loads a thumbnail first and the YouTube player only on click — much faster pages.

Options
px
Code style
Advanced

Only for very old browsers or CMSs that strip the aspect-ratio style.

Preview
Paste a YouTube link to see the preview

The preview loads content from YouTube. If the preview says "Video unavailable", the owner may have disabled embedding.

Code

    

Runs in your browser — your data is not uploaded.

How to use

  1. Paste a YouTube link, existing embed code or 11-character video ID into the input.
  2. Choose 16:9, 9:16 or another ratio under Aspect ratio. Shorts links switch to 9:16 automatically.
  3. Check the preview using Phone 360, Tablet 768 or Full.
  4. Click Copy code to copy the embed code for your page.

Examples

Start a video at 42 seconds

Input
https://www.youtube.com/watch?v=dQw4w9WgXcQ&t=42
Output
<iframe src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?start=42&amp;rel=0&amp;playsinline=1" srcdoc="&lt;style&gt;*{padding:0;margin:0;overflow:hidden}html,body{height:100%}img,span{position:absolute;width:100%;top:0;bottom:0;margin:auto}img{height:100%;object-fit:cover}span{height:1.5em;text-align:center;font:48px/1.5 sans-serif;color:#fff;text-shadow:0 0 .5em #000}&lt;/style&gt;&lt;a href='https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?start=42&amp;amp;autoplay=1&amp;amp;rel=0&amp;amp;playsinline=1' aria-label='Play: YouTube video player'&gt;&lt;img src='https://i.ytimg.com/vi/dQw4w9WgXcQ/hqdefault.jpg' alt='YouTube video player' loading='lazy'&gt;&lt;span&gt;▶&lt;/span&gt;&lt;/a&gt;" title="YouTube video player" loading="lazy" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen style="display:block;width:100%;height:auto;aspect-ratio:16/9;border:0;max-width:800px;margin:0 auto;"></iframe>

Vertical Shorts embed

Input
https://www.youtube.com/shorts/aqz-KE-bpKQ
Output
<iframe src="https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ?rel=0&amp;playsinline=1" srcdoc="&lt;style&gt;*{padding:0;margin:0;overflow:hidden}html,body{height:100%}img,span{position:absolute;width:100%;top:0;bottom:0;margin:auto}img{height:100%;object-fit:cover}span{height:1.5em;text-align:center;font:48px/1.5 sans-serif;color:#fff;text-shadow:0 0 .5em #000}&lt;/style&gt;&lt;a href='https://www.youtube-nocookie.com/embed/aqz-KE-bpKQ?autoplay=1&amp;amp;rel=0&amp;amp;playsinline=1' aria-label='Play: YouTube video player'&gt;&lt;img src='https://i.ytimg.com/vi/aqz-KE-bpKQ/hqdefault.jpg' alt='YouTube video player' loading='lazy'&gt;&lt;span&gt;▶&lt;/span&gt;&lt;/a&gt;" title="YouTube video player" loading="lazy" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen style="display:block;width:100%;height:auto;aspect-ratio:9/16;border:0;max-width:400px;margin:0 auto;"></iframe>

Loop a course playlist

Input
https://www.youtube.com/playlist?list=PLhQjrBD2T382_R182iC2gNZI9HzWFMC_8
Output
<style>.yt-embed{display:block;width:100%;height:auto;aspect-ratio:16/9;border:0;max-width:800px;margin:0 auto}</style>
<iframe class="yt-embed" src="https://www.youtube-nocookie.com/embed/videoseries?list=PLhQjrBD2T382_R182iC2gNZI9HzWFMC_8&amp;loop=1&amp;rel=0&amp;playsinline=1" title="YouTube video player" loading="lazy" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

FAQ

How does click-to-load work?

Click-to-load (lightweight) shows a thumbnail and loads the YouTube player only when you click play. The thumbnail loads immediately from i.ytimg.com, and the generated code needs no JavaScript on your site.

What does privacy-enhanced mode do?

Privacy-enhanced mode (youtube-nocookie.com) uses www.youtube-nocookie.com instead of www.youtube.com for the player in the embed URL. It does not stop all connections to YouTube. The preview on this page still loads a thumbnail or the player, depending on your settings.

How do I enable autoplay for a YouTube embed?

Turn off Click-to-load (lightweight), then turn on Autoplay on page load. The tool also turns on Mute and adds autoplay=1 and mute=1 to the embed URL.

Why does the preview say “Video unavailable”?

The tool generates code without checking whether the video exists or allows embedding. Check the video on YouTube and confirm that embedding is allowed.