YouTube Embed Code Generator
Generate responsive iframe embed code for any video.
Was this tool helpful?
Thanks for the feedback!
Paste a YouTube video link or video ID and this generator returns the standard iframe code for embedding the player on a web page, along with a live preview of the video. It is handy for adding a video to a blog post, a school or college website, an online course page or a hand-coded HTML page.
The code you get
Paste the link and press Get result. The tool extracts the 11-character video ID and places it in this template:
<iframe width="560" height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
The code appears in a box you can copy from, and the player below it shows how the embed will look. Watch links, youtu.be short links, Shorts, live and existing embed links all work, as does a bare video ID. For a watch link, the v= parameter needs to come straight after watch?, as it does in links copied from YouTube.
A few parts are worth understanding. 560 × 315 is a 16:9 frame. The title attribute is read aloud by screen readers, so changing it to describe the video, for example "How to file ITR-1 online", makes the page more accessible. The allow list grants the player permissions such as autoplay and picture-in-picture.
Making the embed fit phone screens
The generated code has a fixed width, so on screens narrower than 560 pixels it can overflow the layout. Add this CSS to your stylesheet to make every embed scale with its container:
iframe { width: 100%; height: auto; aspect-ratio: 16 / 9; }
The aspect-ratio property is supported by all current browsers. On WordPress you often don't need the iframe at all: pasting a YouTube URL on its own line in the editor embeds the video automatically.
Player options you can add to the URL
The generator has no settings, but you can append parameters to the src address yourself. Start the first with ? and join the rest with &, for example https://www.youtube.com/embed/VIDEO_ID?start=90&mute=1.
| Parameter | Effect |
|---|---|
start=90 | Begins playback at 90 seconds (1:30) |
end=150 | Stops playback at 150 seconds |
autoplay=1&mute=1 | Plays on load; most browsers allow this only when muted |
loop=1&playlist=VIDEO_ID | Repeats a single video (the playlist value is required) |
controls=0 | Hides the player controls |
rel=0 | Limits end-screen suggestions to the same channel |
cc_load_policy=1 | Shows captions by default |
Both start and end take whole seconds, so a moment at 12:45 becomes start=765. The timestamp link generator page shows how to work that out, and explains the t= parameter that ordinary YouTube links use instead.
When an embed will not play
- Embedding disabled: a video owner can switch off playback on other websites, and the player then shows an error instead of the video.
- Age-restricted videos cannot be watched in an embedded player; viewers are sent to YouTube.
- Private or deleted videos show as unavailable. Unlisted videos do embed.
For fewer tracking cookies, swap www.youtube.com for www.youtube-nocookie.com in the src, which is YouTube's privacy-enhanced mode. The link you paste is processed in your browser, and only the preview player loads from YouTube.