YouTube Embed Code Generator
Paste a YouTube link to get responsive iframe code you can drop into a page. All processing happens locally in your browser.
How to use
- Paste the YouTube video link above.
- Optionally specify a start time or enable privacy-enhanced mode.
- Click Copy HTML Code and paste the responsive embed into your webpage.
What is a YouTube embed code?
A YouTube embed code is a small piece of HTML that places the YouTube player inside a webpage. The code uses an <iframe> with a URL such as youtube.com/embed/VIDEO_ID, while YouTube handles playback, captions, quality controls and the rest of the player.
YouTube's own embed code usually includes a fixed width and height. That works, but it is not always ideal for a responsive website. This tool creates an embed that can resize with its container while keeping the video's 16:9 shape.
How the responsive embed works
The generated code places the iframe inside a wrapper that uses aspect-ratio: 16 / 9. The wrapper takes the available width and the browser calculates the correct height automatically.
width: 100%lets the player fit the content area.aspect-ratio: 16 / 9keeps the player proportional as the page gets wider or narrower.- The iframe fills the wrapper instead of relying on a fixed desktop size.
border: 0removes the default iframe border.
Older responsive-video examples often use a percentage-based padding trick. That approach still works, but aspect-ratio is easier to understand and is supported by modern browsers.
The generated iframe can also include loading="lazy", which allows the browser to delay loading an off-screen player until it is closer to the viewport. This is especially useful on pages with several videos.
How to generate YouTube embed code
- Paste a YouTube video link. Standard watch URLs,
youtu.belinks, Shorts URLs and existing embed URLs can be parsed when they contain a valid video ID. - Choose your options. Add a start time or use the privacy-enhanced YouTube host if you need it.
- Copy the embed code. Paste the generated HTML into a page or CMS that allows iframe embeds.
If the tool includes a Preview button, the YouTube player is only loaded when you choose to preview it. Generating the HTML itself does not require the video to start playing.
Starting an embedded video at a specific time
YouTube uses different parameters for a normal video link and an embedded player. A shared watch URL often uses t, while an iframe uses the start player parameter.
| Use | Parameter | Example |
|---|---|---|
| Shared video link | t |
youtube.com/watch?v=ID&t=95 |
| Embedded player | start |
youtube.com/embed/ID?start=95 |
The start value is measured in seconds. For example, start=95 asks the player to begin around 1 minute 35 seconds into the video. YouTube may start slightly before the exact second because playback begins from a nearby keyframe.
If you need a shareable link instead of iframe HTML, use the YouTube Timestamp Link Generator.
What does the privacy-enhanced option do?
The privacy-enhanced option changes the embed host from youtube.com to youtube-nocookie.com. YouTube calls this Privacy Enhanced Mode.
According to YouTube, views from a player using Privacy Enhanced Mode are not used to personalize the viewer's YouTube browsing experience. If ads appear in that player, they are also non-personalized.
This does not mean the embed makes your page anonymous or automatically compliant with every privacy law. The visitor's browser still connects to YouTube when the player loads. If your site requires consent before loading third-party content, you may still need to show a placeholder and create the iframe only after the visitor gives consent.
Related videos and the rel parameter
YouTube no longer provides a parameter that completely turns off related videos at the end of playback.
The older rel=0 setting used to disable related videos. Today, setting rel=0 instead tells the player to choose related videos from the same channel as the video that was just played.
Because it does not remove recommendations completely, this tool should not describe rel=0 as a "Disable related videos" option.
Use cases: where can you use the embed code?
- Blog posts. Add a tutorial, interview or demonstration without sending the reader away from the article.
- Documentation. Place a walkthrough beside the instructions it explains.
- Product pages. Embed a demo or introduction and optionally begin playback at the most useful section.
- Course pages. Keep several lesson videos responsive on desktop, tablet and mobile layouts.
- Privacy-conscious pages. Use YouTube's privacy-enhanced player and add your own consent gate when your site's privacy requirements call for one.
The result is ordinary HTML and can be used anywhere that permits YouTube iframes. If you are working in React or JSX, attributes such as allowfullscreen need to follow JSX conventions, for example allowFullScreen. Inline style syntax may also need to be converted to a JavaScript style object.
If you want to clean up the generated markup before adding it to a project, use the HTML Formatter.
Why an embedded video may not play
A valid embed code does not guarantee that every YouTube video can play on every website.
- Embedding may be disabled. Uploaders can turn off embedding for individual videos.
- Age-restricted videos can be limited. YouTube says age-restricted videos cannot be watched on most third-party websites and may send the viewer back to YouTube.
- Private videos remain restricted. An iframe does not bypass the video's privacy settings.
- Unlisted videos can normally be viewed by anyone with the link. They can be embedded when the video is still available and embedding has not been disabled.
- The page must provide normal embed context. YouTube currently requires embedded players to receive an HTTP Referer; opening the raw embed URL directly can produce a playback error.
Privacy and local code generation
If the current implementation parses the video URL in the browser, generating the embed code does not require sending the pasted link to TryFormatter. The video ID and selected options are used locally to build the iframe markup.
Preview is different because it loads the real YouTube player. When you open the preview, your browser connects to YouTube just as it would when the finished iframe appears on a website.
Analytics should record only privacy-safe actions such as whether embed code was generated or whether input validation failed. The pasted video URL, video ID and generated markup should not be included in analytics events.
Frequently Asked Questions
What is a YouTube embed code?
It is an HTML <iframe> that loads the YouTube player inside another webpage. The iframe points to a URL such as https://www.youtube.com/embed/VIDEO_ID.
Why make the YouTube embed responsive?
A fixed-width iframe can overflow a narrow layout or leave unused space in a wider one. A responsive wrapper lets the player follow the available width while keeping its 16:9 shape.
Why does my start time not work in the embed?
YouTube embeds use the start parameter with a value in seconds. For example, ?start=95 begins playback around 1 minute 35 seconds into the video. Shared watch links may use t instead.
Does the no-cookie option make an embed fully private?
No. youtube-nocookie.com enables YouTube Privacy Enhanced Mode, which limits how embedded views are used for personalization. The browser still connects to YouTube when the player loads, so additional consent handling may still be needed depending on your site and applicable rules.
Can I disable related YouTube videos?
Not completely. YouTube changed the behavior of rel=0 in 2018. It now limits related recommendations to videos from the same channel instead of removing related videos altogether.
Can an unlisted YouTube video be embedded?
Usually yes. Anyone with the link can view an unlisted video, and it can normally be embedded as long as the uploader has not disabled embedding and the video has no other playback restriction.
Can a private YouTube video be embedded?
Embedding does not bypass a private video's access controls. Private videos remain limited to authorized viewers, so they should not be treated as publicly embeddable content.
Why does an embedded YouTube video say playback is unavailable?
Possible causes include embedding being disabled by the uploader, an age restriction, private-video permissions, or missing embed context such as the HTTP Referer required by YouTube.
Will this embed code work in React?
The generated output is standard HTML. In React or JSX, you may need to convert attributes to JSX syntax, such as allowfullscreen to allowFullScreen, and convert inline style text into a JavaScript style object.
Why use loading="lazy" on a YouTube iframe?
Lazy loading allows the browser to delay loading an off-screen player until it is closer to the viewport. This can reduce unnecessary work on pages that contain several embedded videos.