EthicalFusion

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.

ParameterEffect
start=90Begins playback at 90 seconds (1:30)
end=150Stops playback at 150 seconds
autoplay=1&mute=1Plays on load; most browsers allow this only when muted
loop=1&playlist=VIDEO_IDRepeats a single video (the playlist value is required)
controls=0Hides the player controls
rel=0Limits end-screen suggestions to the same channel
cc_load_policy=1Shows 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.

Frequently asked questions

How do I make a YouTube embed responsive on mobile?
Give the iframe a width of 100%, a height of auto and an aspect-ratio of 16 / 9 in your CSS. It will then resize with the page instead of overflowing.
How can an embedded video start at a specific time?
Add ?start= followed by the number of seconds to the end of the embed URL, for example ?start=75 to begin at 1:15.
Why does my embedded video show an error instead of playing?
The owner may have disabled embedding, the video may be age-restricted, or it may be private or deleted. None of these can be changed from the embed code.
Can an embedded video autoplay?
Yes, with autoplay=1, but browsers generally only permit it when the video is also muted, so add mute=1 as well.
Can I embed a YouTube Short?
Yes, paste the Shorts link as usual. The code uses a 16:9 frame, so for a vertical Short consider swapping the width and height to 315 and 560.

Related tools

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.