AM Jarvis

YouTube Embed Code Generator

Build a responsive YouTube iframe with start time, autoplay, loop, captions, privacy mode, lazy loading and a 9:16 Shorts option.

YouTube embed code

Size
Aspect ratio
Live preview
The player preview appears here.

In short

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

On this page
  1. How to use the YouTube Embed Code Generator
  2. Where to paste the code
  3. What each option does
  4. Worked examples
  5. Autoplay, loop and captions: the fine print
  6. Parameters that no longer do what people think
  7. Embedding playlists and a channel's latest uploads
  8. Who uses it
  9. Troubleshooting
  10. Getting the most from embedded videos

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

Everything happens in your browser. The only request that leaves the page is the preview player loading from YouTube.

How to use the YouTube Embed Code Generator

  1. Paste a link. Watch links, youtu.be links, Shorts, live links, existing embed links and playlist links with list= all work. The badge under the box confirms whether it found a video, a Short, a playlist, or a video inside a playlist.
  2. Choose the size. Responsive fills the width of its container and keeps its shape. Fixed lets you set width (200 to 3,840 pixels) and height (150 to 3,840 pixels).
  3. Choose the aspect ratio. 16:9 for normal videos, 9:16 for Shorts. A Shorts link switches to 9:16 automatically, and the vertical player is capped at 360 pixels wide so it does not fill a desktop screen.
  4. Set a start time if you want playback to begin partway through. Type 1:30, 1:02:30, 1m30s or plain seconds. If your link already has ?t=, the start time fills in for you.
  5. Tick the options you want: autoplay (muted), loop, hide controls, captions on, privacy-enhanced mode, lazy loading, and related videos from this channel only.
  6. Edit the player title. Screen readers announce it, so describe the video, for example "How to fit a bike chain".
  7. Play the preview to check the start time and captions, then click Copy code. Copy player URL copies just the src address if your platform has its own video block that asks for a URL.
  8. Paste the code into an HTML block, not a normal text field, where it would show as text.

Where to paste the code

PlatformWhere the code goes
Shopify product or pageOpen the rich text editor, click Show HTML (the <> icon) and paste. In a theme section, use a Custom Liquid block.
WordPress and WooCommerceAdd a Custom HTML block in the block editor, or use the Text tab in the classic editor.
Wix, Squarespace and similarUse the Embed or Code block and paste the whole snippet.
Plain HTML sitePaste it where the player should appear inside the page body.

What each option does

Most options are URL parameters documented in Google's YouTube player parameters reference.

OptionCode it addsWhat it does
ResponsiveA wrapper that keeps a 16:9 or 9:16 ratioThe player fills its container on phones and desktops
Start timestart=90Starts playback at that many seconds
Autoplay (muted)autoplay=1&mute=1Plays on page load with sound off
Looploop=1&playlist=VIDEO_IDReplays the video, or the whole playlist
Hide controlscontrols=0Hides the control bar
Captions oncc_load_policy=1Shows captions by default when the video has them
Privacy-enhanced mode (on by default)youtube-nocookie.comViews do not shape the visitor's YouTube recommendations or ads elsewhere
Lazy loading (on by default)loading="lazy"The browser loads the player only when it nears the screen
Related videos from this channel onlyrel=0Limits end-screen suggestions to the same channel

The code also includes referrerpolicy="strict-origin-when-cross-origin", the same value YouTube's own embed code uses, and an allow list for fullscreen, picture-in-picture and autoplay.

Worked examples

A product video that starts at the demo

A Shopify seller has a 6-minute unboxing video where the useful demo starts at 1 minute 45 seconds. She pastes the link, types 1:45 as the start time (the hint confirms 105 seconds), keeps responsive and privacy-enhanced mode, and pastes the code under the product description. Shoppers who press play see the product working, not the packaging.

A looping background clip

A cafe website wants a silent 20-second latte art clip playing on its homepage. Tick autoplay and loop, and hide controls. The generator adds mute=1 for autoplay and playlist= with the same video ID, which YouTube needs to loop a single video.

A Short on a blog post

A recipe blogger pastes a Shorts link. The tool detects it, switches to 9:16 and builds a vertical player capped at 360 pixels wide and centered, so the Short looks the way it does on a phone.

Autoplay, loop and captions: the fine print

Autoplay needs mute. Browsers block autoplay with sound, so the generator always adds mute=1. YouTube's embedding help page also says embedded videos that are autoplayed do not increase the view count, and autoplay loads the player as soon as the page opens, even if the visitor never watches.

Loop needs the playlist parameter for a single video. The generator adds it. For a playlist, loop replays the whole list.

Captions on only works if the video has captions, uploaded or automatic.

Parameters that no longer do what people think

  • rel=0 does not turn off related videos. Since 2018 it only limits them to the same channel as the video playing.
  • 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 title overlay, and visitors can still click through to YouTube.

Note: Privacy-enhanced mode stops embedded views from shaping the visitor's YouTube recommendations and from personalizing ads outside your site, 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 whether your cookie consent setup still needs to cover it in your region.

Embedding playlists and a channel's latest uploads

Paste a playlist URL and the code uses youtube.com/embed/videoseries?list= plus the playlist ID, with a playlist menu inside the player. Paste a watch link that also contains list= and the player starts on that video inside the playlist. To show a channel's newest uploads, find the channel ID with the YouTube channel ID finder, copy its uploads playlist (the ID with UC changed to UU) and paste youtube.com/playlist?list= plus that ID here.

Who uses it

  • Online store owners adding product demos and how-to videos next to the buy button.
  • Bloggers and affiliate site owners embedding reviews to keep readers on the page.
  • Teachers and course creators starting a lesson video at the exact part students need.
  • Creators putting their latest uploads on their own website or link-in-bio page.
  • Developers who want clean, accessible code without writing the wrapper by hand.

Troubleshooting

  • "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.
  • "Error 153: Video player configuration error". YouTube could not read where the player is embedded. Keep the referrerpolicy attribute from the generated code, and check that your site, a security plugin or a server setting is not sending Referrer-Policy: no-referrer or same-origin.
  • The code shows as text. You pasted into a visual editor. Switch to HTML view.
  • Black bars or a squashed player. Your theme sets a fixed height on the iframe. Use the responsive option and remove fixed sizes from the surrounding block.
  • Autoplay does not start. Some mobile browsers and data saver modes still block it, even muted.
  • Slow pages. Each player loads a large bundle of scripts. Keep lazy loading on and avoid more than one or two embeds above the fold.

Getting the most from embedded videos

Keep a product video close to the buy button, start it at the useful part and write a short text summary next to it for visitors who will not press play. Save a full-size poster image with the YouTube thumbnail downloader if your theme uses one. On YouTube itself, a clear description with chapters from the YouTube description generator helps the same video get found, and YouTube Studio in AM Jarvis plans and writes 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 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.

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

On YouTube, click Share under the video, then Embed, and copy the iframe. That gives a fixed size with few options. For a responsive player with start time, autoplay, loop, captions and privacy mode, paste the link into this generator instead.

Can I legally embed a YouTube video on my website?

Yes, if the owner allows embedding, which is on by default. YouTube's Terms of Service let you use the embedded player, and the video stays hosted by YouTube with the owner's ads and branding. You should not download and re-upload someone else's video, and embedding does not give you rights to use the content in other ways.

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. YouTube also does not count autoplayed embeds as views.

Can I embed YouTube Shorts?

Yes. Paste the Shorts link and the generator uses the video ID, switches to a 9:16 vertical player and caps its width at 360 pixels so it looks like it does on a phone. You can switch back to 16:9 if you prefer.

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, 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 or ads outside your site. Normal YouTube data use 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 start at a certain time?

Type the time into the Start time field as minutes and seconds, such as 1:30, and the generator adds start=90 to the player URL. If your link already contains ?t=, the start time is filled in for you. Play the preview to confirm it.