Is it possible to embed an html5 version of a youtube video without using an iframe?
-
2It's possible but not reliable - http://stackoverflow.com/questions/5157377/show-youtube-video-source-into-html5-video-tag. Here's the doc page (doesn't list the previous method): https://developers.google.com/youtube/player_parameters. Just out of interest, why don't you want to use youtube's iframe embed code? – Joe Sep 10 '13 at 18:44
-
2@Joe I've been having memory usage issues with iframes on iOS, so was looking for an alternative. – andrewb Sep 23 '15 at 02:38
-
2YouTube's documentation (as of now) states that iframes are the recommended method for embeds: https://developers.google.com/youtube/player_parameters?hl=en#Embedding_a_Player. They've also deprecated alternate options, e.g. the ` – andrewb Sep 23 '15 at 02:39
-
I have also reason for this , i just want to use youtube videos for webgl texture rendering. I cant do it without src also i need to play it video html5 tag . @andrewb i will try with object tag . – Nikola Lukic Jun 05 '17 at 11:39
-
2@andrewb iframe contents are able to bypass the same-origin policy which means that you'd be giving google the means to access to your IndexedDB databases. – Michael Kargl May 16 '20 at 20:44
5 Answers
Here is a example of embedding without an iFrame:
<div style="width: 560px; height: 315px; float: none; clear: both; margin: 2px auto;">
<embed
src="https://www.youtube.com/embed/J---aiyznGQ?autohide=1&autoplay=1"
wmode="transparent"
type="video/mp4"
width="100%" height="100%"
allow="autoplay; encrypted-media; picture-in-picture"
allowfullscreen
title="Keyboard Cat"
>
</div>
compare to regular iframe "embed" code from YouTube:
<iframe
width="560"
height="315"
src="https://www.youtube.com/embed/J---aiyznGQ?autoplay=1"
frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
and as far as HTML5 goes, use <object>
tag like so (corrected):
<object
style="width: 820px; height: 461.25px; float: none; clear: both; margin: 2px auto;"
data="http://www.youtube.com/embed/J---aiyznGQ?autoplay=1">
</object>

- 1,847
- 20
- 18
-
-
this does not seem to work for iOS... it doesn't want to display the video at all. Does iOS not support – CJT3 Jan 07 '15 at 02:19
-
@CharlesJohnThompsonIII Works for iOS, unfortunately all these options seem to induce memory usage problems if instances are created then destroyed repeatedly. – andrewb Sep 23 '15 at 02:35
-
3
-
1@anapsix Why there are multiple width and height css properties in style attribute of object tag? – Visruth Dec 25 '18 at 04:50
-
-
1
Yes. Youtube API is the best resource for this.
There are 3 way to embed a video:
- IFrame embeds using
<iframe>
tags - IFrame embeds using the IFrame Player API
- AS3 (and AS2*) object embeds
DEPRECATED
I think you are looking for the second one of them:
IFrame embeds using the IFrame Player API
The HTML and JavaScript code below shows a simple example that inserts a YouTube player into the page element that has an id value of ytplayer. The onYouTubePlayerAPIReady() function specified here is called automatically when the IFrame Player API code has loaded. This code does not define any player parameters and also does not define other event handlers.
<div id="ytplayer"></div>
<script>
// Load the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Replace the 'ytplayer' element with an <iframe> and
// YouTube player after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('ytplayer', {
height: '390',
width: '640',
videoId: 'M7lc1UVf-VE'
});
}
</script>
Here are some instructions where you may take a look when starting using the API.
An embed example without using iframe
is to use <object>
tag:
<object width="640" height="360">
<param name="movie" value="http://www.youtube.com/embed/yt-video-id?html5=1&rel=0&hl=en_US&version=3"/>
<param name="allowFullScreen" value="true"/>
<param name="allowscriptaccess" value="always"/>
<embed width="640" height="360" src="http://www.youtube.com/embed/yt-video-id?html5=1&rel=0&hl=en_US&version=3" class="youtube-player" type="text/html" allowscriptaccess="always" allowfullscreen="true"/>
</object>
(replace yt-video-id
with your video id)

- 377
- 4
- 15

- 109,027
- 88
- 289
- 474
-
14
-
1
-
34the question is about embedding an html5 youtube video "without iframe". – taseenb Mar 03 '14 at 11:21
-
-
Well, I added an embed example not using iframe. If HTML5 is enabled, it will be used. If not it probably fallback in flash mode. Not sure if this is what OP wants. – Ionică Bizău Aug 18 '14 at 05:02
Because of the GDPR it makes no sense to use the iframe, you should rather use the object tag with the embed tag and also use the embed link.
<object width="100%" height="333">
<param name="movie" value="https://www.youtube-nocookie.com/embed/Sdg0ef2PpBw">
<embed src="https://www.youtube-nocookie.com/embed/Sdg0ef2PpBw" width="100%" height="333">
</object>
You should also activate the extended data protection mode function to receive the no cookie url.
type="application/x-shockwave-flash"
flash does not have to be used
Nocookie, however, means that data is still being transmitted, namely the thumbnail that is loaded from YouTube. But at least data is no longer passed on to advertising networks (as example DoubleClick). And no user data is stored on your website by youtube.

- 124
- 10
-
3
-
Please explain what is going on and what the url `youtube-nocookie` is doing. In the comments above it was said that flash is not neeed, so why is it needed here? – not2qubit Oct 25 '20 at 11:22
-
@dippas This is not a function but a video in Hypertext Markup Language that is called up in an HTML tag "how your code works" ? Here was the question how to integrate a YouTube video without an iframe. – prod3v3loper Jan 27 '21 at 12:10
Yes, but it depends on what you mean by 'embed'; as far as I can tell after reading through the docs, it seems like you have a couple of options if you want to get around using the iframe API. You can use the javascript and flash API's (https://developers.google.com/youtube/player_parameters) to embed a player, but that involves creating Flash objects in your code (something I personally avoid, but not necessarily something that you have to). Below are some helpful sections from the dev docs for the Youtube API.
If you really want to get around all these methods and include video without any sort of iframe, then your best bet might be creating an HTML5 video player/app that can connect to the Youtube Data API (https://developers.google.com/youtube/v3/). I'm not sure what the extent of your needs are, but this would be the way to go if you really want to get around using any iframes or flash objects.
Hope this helps!
Useful:
(https://developers.google.com/youtube/player_parameters)
IFrame embeds using the IFrame Player API
Follow the IFrame Player API instructions to insert a video player in your web page or application after the Player API's JavaScript code has loaded. The second parameter in the constructor for the video player is an object that specifies player options. Within that object, the playerVars property identifies player parameters.
The HTML and JavaScript code below shows a simple example that inserts a YouTube player into the page element that has an id value of ytplayer. The onYouTubePlayerAPIReady() function specified here is called automatically when the IFrame Player API code has loaded. This code does not define any player parameters and also does not define other event handlers.
...
IFrame embeds using tags
Define an tag in your application in which the src URL specifies the content that the player will load as well as any other player parameters you want to set. The tag's height and width parameters specify the dimensions of the player.
If you are creating the element yourself (rather than using the IFrame Player API to create it), you can append player parameters directly to the end of the URL. The URL has the following format:
...
AS3 object embeds
Object embeds use an tag to specify the player's dimensions and parameters. The sample code below demonstrates how to use an object embed to load an AS3 player that automatically plays the same video as the previous two examples.

- 1
- 1

- 4,391
- 2
- 25
- 38
Use the object tag:
<object data="http://iamawesome.com" type="text/html" width="200" height="200">
<a href="http://iamawesome.com">access the page directly</a>
</object>
Ref: http://debug.ga/embedding-external-pages-without-iframes/

- 59
- 1
- 2