YouTube Embed Code Generator

Build a responsive YouTube iframe with start time, autoplay, loop, captions, privacy mode and lazy loading, then copy it.

YouTube embed code

Size
Aspect ratio
Live preview
The player preview appears here.

In short

The YouTube Embed Code Generator turns a video or playlist URL into iframe code with the options you choose, such as responsive width, start time, muted autoplay, loop, hidden controls, captions, privacy-enhanced mode and lazy loading. Check the live preview, then copy the code into your site's HTML editor.

On this page
  1. How to use the YouTube Embed Code Generator
  2. What each option does
  3. Parameters that no longer do what people think
  4. Embedding playlists and Shorts
  5. Common embedding problems
  6. Getting the most from embedded videos

YouTube's own Share > Embed button gives you a fixed-size iframe with few options. This generator starts from a video or playlist URL, lets you set the player options that matter, shows a live preview and gives you clean iframe code to copy. The code works in any site builder or CMS that accepts HTML, including Shopify, WordPress and WooCommerce.

How to use the YouTube Embed Code Generator

  1. Paste a video URL (youtube.com/watch?v=, youtu.be/ or a Shorts link) or a playlist URL containing list=.
  2. Choose the options: responsive width, start time, autoplay, loop, hide controls, captions on, privacy-enhanced mode and lazy loading.
  3. Watch the preview update. Play it to check the start time and captions.
  4. Copy the code.
  5. Paste it into an HTML or code block on your page, not into a normal text field, where it would show as text.

In Shopify, open the product or page, click the Show HTML button (the <> icon) in the rich text editor and paste the code there. In WordPress, use a Custom HTML block.

What each option does

Most options are URL parameters documented in Google's YouTube player parameters reference. Here is what each does in practice.

OptionCode it addsWhat it does
Responsive widthFull width with a 16:9 aspect ratioThe player fills its container and keeps its shape on phones and desktops
Start timestart=90Starts playback at that many seconds (enter 1:30 and the tool converts it)
Autoplay (muted)autoplay=1&mute=1Plays on page load, with sound off
Looploop=1&playlist=VIDEO_IDReplays the video when it ends
Hide controlscontrols=0Hides the control bar
Captions oncc_load_policy=1Shows captions by default when the video has them
Privacy-enhanced modeyoutube-nocookie.com domainLimits how embedded views are used for personalization
Lazy loadingloading="lazy"The browser loads the player only when it nears the screen

Autoplay needs mute

Modern browsers block autoplay with sound, so an unmuted autoplay embed usually just sits there. The generator always adds mute=1 when you turn autoplay on. Two more things to know: YouTube's help pages say autoplayed embeds do not increase the video's view count, and autoplay loads the player and starts data collection as soon as the page opens, even if the visitor never watches.

Loop needs the playlist parameter

For a single video, loop=1 only works when playlist is set to the same video ID. The generator adds it for you. For a playlist, loop replays the whole playlist.

Captions depend on the video

Captions on only works if the video has captions, either uploaded by the creator or generated automatically. If there are none, the setting does nothing.

Parameters that no longer do what people think

  • rel=0 does not turn off related videos. Since 2018, rel=0 only limits them to videos from the same channel as the one playing. You cannot remove them entirely.
  • modestbranding is deprecated and has no effect, so the generator leaves it out.
  • showinfo was removed years ago. Old tutorials still include it.
  • Hiding controls does not remove the YouTube logo or the title overlay, and it does not stop visitors from clicking through to YouTube.

Note: Privacy-enhanced mode stops embedded views from shaping the visitor's YouTube recommendations and serves non-personalized ads, but it is not the same as no tracking. Once a visitor plays the video or clicks through to YouTube, normal YouTube data use applies. Check with your cookie consent setup whether it still needs consent in your region.

Embedding playlists and Shorts

For a playlist, paste the playlist URL. The code uses youtube.com/embed/videoseries?list= plus the playlist ID and shows a playlist menu inside the player. To embed a channel's latest uploads, find the channel ID with the YouTube channel ID finder, replace the leading UC with UU, and use that as the playlist ID.

Shorts embed like normal videos. Paste the Shorts link and the tool uses the video ID. Shorts are vertical, so switch the aspect ratio to 9:16 if the generator offers it, or place the player in a narrow column.

Common embedding problems

  • "Video unavailable" in the player. The owner turned off embedding, the video is private, or it is blocked in the visitor's country. Unlisted videos can be embedded.
  • The code shows as text. You pasted into a visual editor. Switch to HTML view.
  • Tall black bars. Your theme wraps the iframe in fixed-height CSS. Use the responsive option and remove fixed width and height from the wrapper.
  • Slow pages. Each player loads a large bundle of scripts. Turn on lazy loading, and avoid more than one or two embeds above the fold.

Getting the most from embedded videos

A product video on a product page can answer the questions shoppers would otherwise email you about. Keep the video close to the buy button, start it at the useful part with a start time, and write a short text summary next to it for visitors who will not press play. If you want a custom poster image, save the video's full-size thumbnail with the YouTube thumbnail downloader. To get more from the video itself on YouTube, the YouTube description generator builds a description with chapters, and YouTube Studio in AM Jarvis helps plan and write titles, descriptions and tags for the next videos.

Frequently asked questions

How do I embed a YouTube video on my website?

Paste the video URL into the generator above, choose your options and copy the iframe code. Paste it into an HTML block or the HTML view of your editor. In Shopify, use the Show HTML button in the rich text editor. In WordPress, use a Custom HTML block.

Why will my YouTube embed not autoplay?

Browsers block autoplay with sound. Add mute=1 along with autoplay=1, which the generator does for you. Some mobile browsers and data saver settings still block autoplay. Also note that YouTube does not count autoplayed embeds as views.

Can I hide related videos at the end of an embedded YouTube video?

Not completely. Since 2018, rel=0 only limits related videos to the same channel as the video being played. If the video is yours, that means viewers see more of your own videos, which is often a good result.

What is youtube-nocookie.com?

It is YouTube's privacy-enhanced embed domain. Views of videos embedded this way do not influence the visitor's YouTube recommendations, and ads are non-personalized. Normal YouTube tracking still applies once the visitor clicks through to YouTube, so check whether your cookie consent setup still covers it.

How do I make a YouTube embed responsive?

Set the iframe to 100% width with a 16:9 aspect ratio instead of fixed pixel sizes. The generator's responsive option does this, so the player fills its container and keeps its shape on phones, tablets and desktops.