HomeToolsVideo Tools › YouTube Embed Code Generator

YouTube Embed Code Generator

Live

Build a clean, privacy-friendly YouTube embed in seconds. Choose start and end times, autoplay, mute, loop, captions, "no related videos", and a responsive 16:9 wrapper — then copy ready-to-paste HTML.

Player options

About YouTube Embed Code Generator

When you paste a YouTube URL into a website builder, you get a basic iframe with YouTube's defaults: related videos from other channels appear after playback, tracking cookies fire on page load before the visitor presses play, the iframe breaks proportions on mobile viewports, and if you needed the video to start at 2:15 and stop at 4:45, you'd need to know the URL parameter syntax to do it manually. None of this is configurable through YouTube's standard embed dialog.

The AT USE YouTube Embed Code Generator controls every YouTube iframe parameter that matters for a production embed. Privacy-enhanced mode routes the embed through youtube-nocookie.com, which delays setting tracking cookies until the visitor actually clicks play — compliant with GDPR and ePrivacy Directive requirements without requiring a consent gate that blocks the video. Start time and end time set the exact clip range to the second. Autoplay pairs automatically with mute (the only configuration modern browsers allow for autoplay). Loop, default captions, and the related-videos setting are single checkboxes. The responsive wrapper option outputs a fluid 16:9 container that scales the iframe correctly from a 375px phone to a 2560px desktop.

The output is plain HTML — no JavaScript framework, no npm package, no third-party dependency. Copy the code block and paste it into any CMS, static site generator, email template, or documentation page.

Parameter reference

Privacy-enhanced mode switches the embed host from youtube.com/embed/ to youtube-nocookie.com/embed/. YouTube's nocookie domain delays all tracking cookies until the user initiates playback. This satisfies the GDPR legitimate-interest threshold for embedded video under most EU data protection authority guidance — the embed loads, the user sees the video preview, no cookies fire unless they choose to play.

Start and end time are passed as start=N and end=N integer seconds. The generator converts mm:ss and hh:mm:ss inputs to the correct integer values. For end time to work reliably, the JavaScript API must be enabled — the generator adds enablejsapi=1 automatically when end time is set.

Autoplay + mute are always paired. Chrome 66, Safari 12, Firefox 61, and every browser since 2018 blocks autoplay of audible content unless the user has previously interacted with the page. Muted autoplay is permitted. If you need audio on load, the browser policy makes that impossible for new visitors — a click-to-play poster setup is the alternative.

Loop requires playlist={video_id} alongside loop=1 — the generator adds both parameters automatically. Note that YouTube's loop always returns to timestamp 0, not to the custom start time.

Hide related videos adds rel=0. Since 2018, this shows only videos from the same channel at the end of playback rather than zero related videos — a meaningful improvement over the default but not a complete suppression.

Responsive wrapper outputs the standard CSS aspect-ratio container: a relative-positioned div with padding-top: 56.25% (the 16:9 ratio) containing an absolutely-positioned iframe that fills 100% width and height. This pattern works in every browser back to IE9 without any JavaScript or CSS framework dependency.

Common use cases

  • GDPR-compliant landing page video: A marketing team launching a product page for EU audiences needs to avoid cookies firing on page load before user consent. Enabling privacy-enhanced mode means the embed loads without setting any tracking cookies — the video preview is visible, the page looks complete, and no consent gate is required. Cookies only fire if the visitor clicks play.
  • Deep-linking to a specific segment in a longer video: A support team publishes a 45-minute setup walkthrough and needs to embed only the 3-minute authentication step (at 12:30 to 15:30) in a documentation article. Setting start to 12:30 and end to 15:30 produces an embed that opens at that exact point and stops when the step ends — keeping the article focused without requiring a separately recorded short clip.
  • Silent autoplay loop for a homepage section: A company uses a 15-second product demo as a background element in the hero section. Setting autoplay + mute + loop produces an embed that starts silently on page load and loops without user interaction — compliant with every browser's autoplay policy and functional on first paint for all visitors.
  • Course and e-learning lesson embeds without related-video distraction: An online course platform embeds all video lessons from YouTube. Setting rel=0 prevents competitor or off-topic videos from appearing in the "up next" panel at the end of each lesson. Setting cc_load_policy=1 forces captions on by default, satisfying WCAG 2.1 SC 1.2.4 for pre-recorded audio without requiring each learner to manually enable them.
  • Email newsletter video preview: Several major email clients (Apple Mail, iOS Mail, Outlook Web) render iframes with click-to-play behavior. Generating a responsive embed with a specific start time drops into a newsletter as a video preview that plays inline in supporting clients and links to YouTube on click in those that do not support embedded video — a single code block that works across both cases.

How to use it

  1. Paste the YouTube URL of the video you want to embed.
  2. Choose your options: privacy mode, start/end time, autoplay, mute, loop, captions, related videos.
  3. Preview the live embed and adjust until it looks right.
  4. Copy the generated HTML and paste it into your page.

Frequently asked questions

Why does autoplay not work even when I enable it?

Every modern browser (Chrome 66+, Safari 12+, Firefox 61+, Edge 79+) blocks autoplay of audible content unless the visitor has previously interacted with the domain. The generator pairs autoplay with mute automatically — muted autoplay is allowed and will work. Unmuted autoplay is blocked for new visitors regardless of embed settings.

What does "Hide related videos" actually do?

The rel=0 parameter limits the "up next" panel to videos from the same YouTube channel rather than unrelated recommendations. YouTube removed the ability to hide all related videos entirely in 2018. rel=0 still provides a meaningful improvement for embedded content — it stops a competitor's video from appearing as the suggestion after your content plays.

Will privacy-enhanced mode break anything?

No. youtube-nocookie.com is an official YouTube domain that serves the same player and video content. Start/end times, autoplay, loop, captions, and all other parameters work identically. Some corporate networks that whitelist YouTube domains explicitly may need youtube-nocookie.com added to their allowlist — but for standard deployments, there is no functional difference.

My loop does not return to the start time I set — it goes back to 0:00.

This is a YouTube iframe API limitation. The loop parameter always returns to the beginning of the video (0:00), not to a custom start time. Looping a specific segment requires custom JavaScript via the YouTube Player API, which an iframe embed cannot do without additional code outside this generator.

Can I use this for YouTube Shorts?

Yes — Shorts URLs are parsed the same as regular video URLs. However, Shorts are vertical (9:16) content. The responsive wrapper defaults to 16:9 (padding-top: 56.25%). For a portrait embed, change the padding-top value in the wrapper from 56.25% to 177.78% to get a 9:16 container.

Is this free?

Yes. No account required, no watermark, no usage limit. The generator runs entirely in your browser and does not send any data to our servers.

Keep going

More video tools

Other tools in the Video category on AT USE.

Live Video Tools

YouTube Thumbnail Downloader

Grab any public YouTube video thumbnail in all official sizes — instantly, no login.

Open tool
Live Video Tools

Video Aspect Ratio & Resolution Calculator

Solve width, height, or aspect ratio for any video — with presets for 16:9, 9:16 Shorts, square, and ultrawide.

Open tool
Live Video Tools

YouTube Timestamp Link Generator

Build deep links to specific moments in a YouTube video. Bulk convert chapter lists in one paste.

Open tool
Live Video Tools

YouTube Chapter Marker Generator

Format your timestamp list into a YouTube-compliant chapter description block.

Open tool
Live Video Tools

Vimeo Embed Code Generator

Generate Vimeo embed code with DNT mode, custom color, autoplay, loop, and a responsive wrapper.

Open tool
Live Video Tools

Subtitle Format Converter

Convert subtitles between SRT, VTT, ASS, SBV, and plain TXT — entirely in your browser.

Open tool