On this page
- Create the perfect YouTube embed code
- How to generate an embed code
- Every option explained
- Why responsive embeds matter
- Autoplay: what works and what does not
- Embeds and website speed
- Privacy-enhanced mode and privacy laws
- Looping a single video
- Embedding Shorts
- Adding the code in popular platforms
- Related tools
- Troubleshooting embeds
Create the perfect YouTube embed code
YouTube’s built-in share menu gives you a basic embed code, but it has a fixed size that breaks on mobile, and most useful options are hidden. The YouTube Embed Code Generator builds clean, modern code in seconds: responsive layout that fits any screen, start and end times, muted autoplay, looping, hidden controls, forced captions, privacy-enhanced mode and lazy loading for faster pages. Every change updates the code instantly, and you can show a live preview before copying it into your website, blog, landing page or email builder.
How to generate an embed code
- Paste the video link. Any YouTube format works, including Shorts and youtu.be links.
- Choose your options. Responsive, privacy-enhanced mode and lazy-loading are switched on by default because they are best practice for most websites.
- Copy the code and paste it into an HTML block in WordPress, Webflow, Wix, Squarespace, Shopify, Blogger or your own HTML.
Every option explained
| Option | What it does | Parameter |
|---|---|---|
| Responsive | Keeps a 16:9 shape and fills the width of its container on every device | CSS aspect-ratio wrapper |
| Privacy-enhanced mode | Loads the player from youtube-nocookie.com, which avoids storing viewing information about visitors until they play the video | youtube-nocookie.com domain |
| Lazy-load | Delays loading the player until the visitor scrolls near it, making your page faster | loading=”lazy” |
| Start at | Begins playback at a chosen time | start= |
| End at | Stops playback at a chosen time | end= |
| Autoplay (muted) | Starts automatically. Browsers only allow this when the video is muted | autoplay=1&mute=1 |
| Start muted | Plays without sound until the viewer unmutes | mute=1 |
| Loop | Restarts the video when it ends | loop=1&playlist=ID |
| Hide controls | Removes the control bar for a cleaner look | controls=0 |
| Show captions | Turns on captions by default when available | cc_load_policy=1 |
| Related videos | Limits suggestions at the end to videos from the same channel | rel=0 |
Why responsive embeds matter
The default YouTube embed is 560×315 pixels. On a phone that is wider than the screen, so it either overflows the layout or gets squashed by the theme. A responsive embed uses the CSS aspect-ratio property to stay exactly 16:9 at any width, from a narrow phone column to a full-width desktop hero section. It is the single most important improvement over the default code and is supported by all modern browsers.
If you need a fixed size, for example in a sidebar widget, untick Responsive and set the width and height you want.
Autoplay: what works and what does not
Chrome, Safari, Firefox and Edge block videos that try to play with sound before the visitor interacts with the page. That is why the generator always adds mute=1 when you choose autoplay. Even then, some browsers on battery-saving mode or with data saver enabled may refuse to autoplay. Use autoplay sparingly: a video that starts on its own can annoy visitors, and it uses their data.
Embeds and website speed
Each YouTube player loads several hundred kilobytes of scripts. On a page with several videos, that adds up and can slow down your Largest Contentful Paint and Interaction to Next Paint scores. Lazy-loading means the player is only loaded when the visitor scrolls close to it, which keeps the first view of your page fast. For pages with many videos, you can go further and show only a thumbnail, from the Thumbnail Downloader, that links to the video or loads the player on click.
Privacy-enhanced mode and privacy laws
When privacy-enhanced mode is on, YouTube says it does not store information about visitors to your page unless they play the video. That makes it a sensible default for websites that serve visitors in the EU and UK, though once a visitor presses play, YouTube’s normal data practices apply. Mention embedded YouTube content in your privacy and cookie policies, and if your site uses a consent tool, consider blocking embeds until consent is given.
Looping a single video
YouTube’s player only loops playlists. To loop one video, the embed must include both loop=1 and a playlist parameter containing the same video ID. The generator adds both automatically when you tick Loop.
Embedding Shorts
Shorts can be embedded like any video using their ID. They will play in the standard player, so consider a vertical container if you want them to appear in their original shape. For a 9:16 layout, change aspect-ratio:16/9 to aspect-ratio:9/16 in the copied code and set a maximum width such as 360px.
Adding the code in popular platforms
WordPress: add a Custom HTML block and paste the code. Wix and Squarespace: use an Embed code or Code block. Shopify: switch the rich text editor to HTML view or use a custom liquid section. Webflow: add an Embed element. Email: most email clients do not support iframes, so link a thumbnail image to the video instead.
Related tools
To share a link that starts at a specific moment rather than embed the video, use the Timestamp Link Generator. To pull IDs out of a long list of links, use the Video ID Finder.
Troubleshooting embeds
“Video unavailable” in the player. The owner has disabled embedding, the video is private, or it is blocked in the viewer’s country. Only the owner can change this, under the video’s advanced settings in YouTube Studio.
The video is cut off or shows black bars. Your theme may set a fixed height on iframes. The responsive code here uses an explicit wrapper, which overrides most theme styles. If bars remain, the video itself was recorded in a different aspect ratio.
Start time is ignored. Check that you entered the time as mm:ss or seconds, and that the end time, if any, is later than the start time.
The page builder strips the code. Some editors remove iframes from normal text blocks for security. Always paste embed code into a dedicated HTML, code or embed block.
Autoplay does not start on iPhone. iOS can block autoplay in Low Power Mode. This is a device setting and cannot be overridden by any embed code.
Frequently Asked Questions
How do I make a YouTube embed responsive?
Enable the Responsive option. The tool wraps the iframe so it keeps a 16:9 ratio and fills the width of any container, from phones to wide desktops, using the modern CSS aspect-ratio property.
Why does autoplay not work?
Browsers block autoplay with sound. When you tick Autoplay the tool also adds mute=1, which is the only reliable way to make an embedded video start automatically.
What is privacy-enhanced mode?
It loads the player from youtube-nocookie.com, so YouTube does not store viewing information about your visitors until they press play. It is a good default for sites that care about privacy laws.
Can I loop a single video?
Yes. Tick Loop and the tool adds both loop=1 and the required playlist parameter with the same video ID, which is how YouTube expects a single video loop to be set up.