If you've ever validated an otherwise XHTML 1.0 compliant website that embedded a video from YouTube, you've probably seen validation errors related to YouTube's use of the <embed> tag, which has been deprecated in XHTML 1.0.
If you're looking to embed a YouTube video in your website's code and want to retain your validity, instead of using their suggested format:
<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/7_6B6vwE83U"></param><embed src="http://www.youtube.com/v/7_6B6vwE83U" type="application/x-shockwave-flash" width="425" height="350"></embed></object>
Use the following format:
<object type="application/x-shockwave-flash" style="width:425px; height:350px;" data="http://www.youtube.com/v/7_6B6vwE83U"><param name="movie" value="http://www.youtube.com/v/7_6B6vwE83U" /></object>
You'll notice that the new format leaves out the <embed> tag and still functions correctly when embedded in your web page.
Props to the K2 Community Forums for pointing me to the Spanish explanation of this technique.
Comments
Thanks for the tip mate. Saved me at least 30 minutes worth of pouring through the W3 specs looking for the correct codebase.
Also -
So one should instead write the following . . .
Either way is correct by the way. It is a matter of using CSS to define the paramater versus attributes within the object tag.
hey thanks for the help!
I was pouring over the different sources trying to look for plugins and codes and files.
Didn't know by using another code, it solves the problem!
woo hoo! i'm so happy! :)
My first youtube video at www.RisingIMStar.com
Thanks alot! :)
Hi Bernie
Thanks for the code. Really appreciate your effort.
Well, you heard of the latest Google deal right?
Here it is www.alexsintq.com
Cheers
Alex
Will, TOFU: I think you'll find it's "poring" although if either of you has noticed sparks and smoke coming from your monitor, and it also seems to have stopped working, then perhaps "pouring" was the correct term after all ...
Mike
Thanks that's brilliant. Been looking at all sorts of mind bending solutions with reams of code. This is short, simple and sweet.
Thanks a lot! i was just looking for this and it works perfectly!
Thanks for the tip mate. Was struggling to work out why the YouTube standard code wasn't working in my Wordpress blog. This solved the problem right away.
Cheers :)
// i'm from Turkey, sorry for my english :(
I use this code for valid xhtml coding for a long time...
---------------------------------------------------------
<object
type="application/x-shockwave-flash"
data="../images/yazi.swf"
width="383" height="39" title="www.huseyindeniz.net">
<param name="movie" value="../images/yazi.swf" />
<param name="quality" value="high" />
<param name="Menu" value="0" />
<param name="WMode" value="Transparent" />
<param name="swliveconnect" value="true" />
</object>
---------------------------------------------------------
it works on all browsers but a new problem occured.
If a preloader exists in flash, that preloader does'nt work on IE7
in my website (www.huseyindeniz.net) there is no preloader and it works
but in www.yazkardesim.com a preolader exists in flash and do not work on IE7. so i use embed tag and it works on ie7. i think there is a problem between ie7, object tag and flash preloading functions. Is there any solution for this problem.
Thanks
---------------------------------------------------------
// Sorry for my english again, i hope you understand my problem :)
Thanks for this. Awesome-ly helpful.
YouTube videos have been the thorn in my valid side for a while now!
This code works fine, but there is a white edge around the player. I solved that using this code:
<object type="application/x-shockwave-flash" style="width:425px; height:350px;" data="http://www.youtube.com/v/ulakMBcqyPo"><param name="movie" value="http://www.youtube.com/v/ulakMBcqyPo" /><param name="wmode" value="transparent"></param></object>
All I did was to add <param name="wmode" value="transparent"> to the code.
Thanks a million, worked without a problem!
Internet Explorer has always had problems with supporting the standards correctly.
i cant thank you enough..my whole blog was based on you tube and IE was such a mess with embed code..
Thanks so much! I was scratching my head trying to find a valid tag for adding a gameplay video for my game off of youtube.
Saved a lot of time...just got here via first page of google....great cool trick.....thanx for it.
Hey... Im so glad I found your site as I have been having problems with the different plugins Ive used to display youtube videos. Yours is the best method by far. Thanks!
Thanks for this. It saved me a lot of time and is so much cleaner.
thanks for this post, it's very useful.
Thank you for the tip, I wonder why YouTube gives us W3 invalid codes?
Thanks for this tip. Now Youtube videos show good using IE 7. My web site is in spanish. Gracias
Is there a way to add code that will replace the still image that YouTube provides? Their still is a video grab and is low-res. I'd like to modify the code to make it find a JPG on my website, but then play the video from YouTube.
Thanks.
This is my very first time on this blog, I found you by googling "embedding youtube".
I want to exclaim that this is the most beautiful blog (by design) I have ever seen !
Hey thanks for the code guys, however -
It works great in Firefox but doesn't in IE 7...
Here is my code...What am I doing wrong???
<object type="application/x-shockwave-flash" style="width:160px; height:132px;" data="http://www.youtube.com/v/g_bK1IHTr5E"><param name="movie" value="http://www.youtube.com/v/g_bK1IHTr5E" /><param name="wmode" value="transparent"></param></object>
For those who were having an IE issue like I was, I figured out the perfect code that works in both IE and Firefox and is XHTML compliant:
<object type="application/x-shockwave-flash" width="400" height="329" data="http://www.youtube.com/v/g_bK1IHTr5E"><param name="movie" value="http://www.youtube.com/v/g_bK1IHTr5E" /><param name="wmode" value="transparent" /></object>
By the way, my previous post addressed the issue of changing the width and height of a YouTube embedded video (aside from its default, 425x300 width and height) - apparently, when using the code given by this site, for some reason functionality is lost when a video is resized using this site's code.
The code in my previous post can be used for videos that are resized - maintaining its XHTML compliance and function in IE and Firefox.
Hi,
This is great! I use it every time.
James
thanks very much!
It's good but there's a white border around the edge. Is there anyway to fix that?
John, scroll up to Sigurd's comments and you should see how to get rid of the white border using the optional wmode parameter.
I'm finding this embedded code. I have got validation errors when i first embed it. But after tried your embedded code, it's work now. Thanks for your info!
Helped me alot with w3c standards!
I want my YouTube video to automatically start playing rather than waiting for the watcher to click on the arrow button. The old way let me do that with an autoplay parameter, as shown below. How can I do what I want with the new scheme?
<embed src="http://www.youtube.com/v/S-mkR-KoPts&NR&
autoplay=1" type="app (and so on).
Laer
I hit the Post Comments button only once, but I got THREE darned posts!
I accidentally found the answer. Change the following
data="http://www.youtube.com/v/VIDEOID"
to
data="http://www.youtube.com/v/VIDEOID&autoplay=1"
And thanks much Bernie. Oh, and I love the color scheme. Very easy on the eyes, and attractive.
Thanks for posting your findings, Laer, and thanks for the compliments.
The thing is it is not work with YouTube customized player...
Yes, this is one of the best features of youtube. I love it
I have done your embed code to my site, it's work well. Thanks for sharing this tip!
Lets sum:
- got rid of
- got rid of white background with transparent
- got video on autaplay
problm: IE doesnt autoplay but shows no border
FF autaplays but shows white border (on non-white background)
:) help!
Hmm, sometimes it says... "the member that submitted this video has disabled embedding" or something like that.
I hate it when that happens. Any ways to avoid that?
The only way to avoid the "embedding disabled" issue, as far as I know, anyway, is to contact the person who originally submitted the video and ask them to enable embedding.
Thank you so much.
It baffles me why sites such as youtube don't give code that will validate. My shopping cart provider does the same thing even though it would be very simple for them to fix.
My working example can be seen here:
http://www.fenixtorch.co.uk/led_torches/lockblock.html
Thanks for the code!
Great! Thanks! It's not validness that is good, it's also a clue to my puzzle of finding the youtube video swf address!
finally xhtml compliance on every page!!!
thank you VERY much Bernie :)
oh, and just to share what i found to be working too:
you can even use FlashVars as a parameter like
<param name="FlashVars" value="the=variables,you=want,to=pass,to=flash" />
:)
hi
a.
at work and in some other places, youtube website is blocked, on my website I want to put videos from my youtube account, how can i convert it to a video that everyone can access eventhough the codes are from my youtube account? not unless, I have the original mp4 video with me, how can i get the embedded codes on that one, is there a way to do that?
b. if i have a mp3 songs and want to put it in my website, how do I get the embedded codes? because i want to put music on my website.
c. what about the slideshows for my pictures? how can i get the embedded codes on this one as well
Thank you for sharing this, it is a GreaT Help!
Thanks, but what if i want to add some other options like play=true or menu=true?
This wont work..
Any ideas?
Kevin
hmmm... I was looking for a way, that's cool to validate w3c but you don't have the small preview before playing the video, and that's not really cool...
i embed your code, its working fine, thanks allot for sharing this Tips.
Thanks! I had the validation figured out but couldin't get my z-index to work properly!
is there anyway to remove those youtube logos from the videos while playing on my site?
Thanks, it helped me deliver a XHTML valid 3D model design site here: http://www.3dmodeldesign.co.uk
Good Morning,
Trying to get this object to embed correctly in DW4 and it recognizes the Activex Control but still appears as a Greg Box on the page, and online it is a white BOX. Very frustrating.
Any ideas on how I can embed this to show correctly? I am able to get it to work on the blogsite http://www.donniepick.blogspot.com but not in the website.
help
Fantastic......... Thankyou very much!!! My Youtube videos wouldnt show in IE7 and this solved the problem 100% and i found this site in seconds ......
Hi. Found your site by chance when looking for a valid xhtml way to embed google videos. I posted a link to your post as the good solution(s) within with a post about "zero errors policy" on validation over at my blog.
I need to have a YouTube player that will search YouTube and will find automatically the last 20 videos that have been uploaded with a spesific key word. The player must be able to be embeded into ASP pages and PHP pages. it must look like the regular YouTube player
Unfortunately, it doesn't appear this method works with IE6.
This post was of great help! I was really starting to stress out at one point with the YouTube code breaking my CSS.
Thanks, Bernie!
Thanks Bernie for the code.
Bernie, thanks for the blog post.
Thomas, thanks for the code. It worked best for me, in getting both ff and i.e. working.
I wish I could figure out how to encourage Serendipity to accept the code rather than formatting it as text...
~~~
Spread Love...
BlueBerry Pick'n
can be found @
ThisCanadian
~~~
"We, two, form a Multitude" ~ Ovid.
~~~
"Silent Freedom is Freedom Silenced"
Hi,
I would really like to know why the code for an youTUBE embedded does not work on eBay auction sites is there more or less needed?
WOOPS!!
ok , yep it works here but not for yahoo email or some html sites either. Please someone could provide the embedded code especially for ebay.
Thanks everyone...
WOW, thanks a lot! If I'd have found this sooner I woudn't have wasted 4 hours trying to figure out why it doesn't work.
website's in production. This was a most valuable resource as I am developing the site to be completely standards compliant.
Cheers! ;-)
Incredibly this post is still highly relevant 2 years later. My solution to the problem, a php preg_replace that changes the code automatically so I can still be lazy and copy the code directly from youtube. Thanks for the post
Hey guys, thanks for all the help with all the codes and all. It's a pretty resourceful page. I am trying to embed code into my Facebook account. If only I could create a automatic loading video that plays when users visit my site....then again, why would uses want stuff starting up without their consent or activation....but, maybe that's what they get as the result of visiting mysite, however, I don't own Facebook, dammit.
Can you get title, descrition and other details by using vedio_id of youtube.
I have vedio_id and using php 4.3 version. Please tell me, can we get the other details using vedio_id.
Great Share!!!!!!!!!!!!!!!!!!!!!!!!!!
Thanks for the tip! Still works fine!
Great information! I could kiss you.
This had been preventing me from adding videos to my sites for some time.
This piece of code was very helpful. it is working fine. saved a lot of time.
thanks buddy!!!! keep up the good work...
:)
Thanks, Bernie, for the fast and easy tip...perfect. Beautiful blog as well. Cheers to you.
thanks a lot for the solution! greets from romania
Glad to see that after 2 years, this method still works. Thanks a bunch!
Once again, a google search for a issue I'm encountering leads me to a Bernie solution. Thanks again!
Really helpful! Thank you.
Thank You
My buddy Jim and I over at Done21.com noticed that a lot of people on the web were having this same problem, so we made a free tool, called Validifier, to help make it a lot easier.
Check it out at http://validifier.com/
Hope this helps someone. :D
Pretty cool tool, Nick. Thanks for sharing the link.
Thanks a lot, really! Your code has saved me from rotting at my computer for several hours! My praises to you ;)
Works great, even over two years later, but what about allowing fullscreen? With the above code, it doesn't work; when I put this into the object tag -- allowfullscreen="true" -- it's invalid again.
Oh well, more Googling to be done.
Vowels, remember, the <param> tag is your friend. I bet if you drop the allowfullscreen/true name/value pair in one of those, you'll be golden.
By the way, this does not work with "Page Style" equals to "No Style" (this is in terms of Firefox's menus). The original YouTube code works.
Totally awesome - been looking for this solution for whats seems like a lifetime now. *hat tips* much respect!
The code works fine in Firefox and IE7, the problem is that it doesn't show anything in IE6 and earlier!
so what's the solution for that?
grazie mille. la soluzione funziona alla perfezione. grazieeeee
FIELD_MESSAGE_elcorolget
It works fine in IE6 and IE5.5 so whats the problem. Thankyou for solving this problem for me.
Thank you SO much for this XHTML valid YouTube code!
I was going nuts trying to validate my stepdaughter's site. :)
I have a micro-blogger that I built and users can embed their own Youtube! videos. I don't want to try to change the tags programatically so that it validates. Are there any versions of HTML/XHTML that allow for Youtube! embed code to validate as it is?
Thanks for the code! Works great! The code was used in a a site that helps musicians get back their stolen music instruments by publicizing instrument thefts to the music community. Rock on!
www.ScreamingStone.com
Cool site, Chris. Thanks for dropping by.
HUGE PROPS!
3 years later and still rockin!
Thx so much!
Gee, am I an excited standardista or what? :-)
What's the right code for IE?
It's not work with IE7 :(
http://widgets.opera.com/widget/10262/. Converts to XHTML Strict
I'm embedding a lot of videos from YouTube into my website and since I'm very concerned about the W3 validity I check every subpage against the compliance with the specs.
The errors generated by YouTube videos was a real pain in the neck. Now, after the mods, all my pages with videos embedded work like a charm!
Thanks for posting this tip, I'll be looking around your website for more useful articles.
I'm trying to get rid of the validation errors at http://www.sytru.com/norton-antivirus but the YouTube videos still generate errors, even after having modified them according to your suggestions.
Is there a way I can workaround this?
Thanks in advance for any hints.
Nice, extremely handy!
Thank you so much for providing an alternative code for the YouTube. I couldn't find one anywhere, and YouTube and other embed src were not validating.
Do you by any chance know how to use CSS for video's style, for example height and width? Please let me know, if you know how to.
Thanks again.
It would be nice to have a PHP script that changed a Youtube! embed code into valid XHTML.
Thanks for the tips! :)
wow a 3 yr old thread!!
Thanks for this post - helped alot, 3 years on... who would have thought! lol
You can now use the freely available swfobject library to embed youtube videos in your web applications. The following examples show you how to embed youtube videos in this way and bonus tricks:
http://911-need-code-help.blogspot.com/2009/05/embed-youtube-videos-in-your-web.html
http://911-need-code-help.blogspot.com/2009/05/embed-multiple-youtube-videos-in-your.html
dear,
this script is very helpful
but is there a way to embed a video without specifying the ID, in a way that everyday to embed the most recent one???
in our website, we need to embed everyday the recent Video from our channel.
so i'am asking if there is a way without each time to enter and change the code manually...
thanks a lot
any suggestion please...
@zbibo, your post looks oddly familiar. Did you look at YouTube custom players:
http://www.youtube.com/my_players
A custom player plays videos from specified YouTube account or playlist. Probably the most recent one is played first which i think is close enough for your needs.
Unfortunately, this doesn't work at the Last.fm, precisely at the "About Me" box in a user's profile at the Last.fm.
Both the code given at the top of this page and the code produced by Nick Pettit's "validifier" are not functional at the Last.fm. :(
However, a clip from the Youtube can be posted to the Last.fm using this form: [youtube]http://www.youtube.com/watch?v=BHM5jsuoL[/youtube]
I'd appreciate it a lot if someone would provide a code or a form to post a Youtube clip of small dimensions (320 x 265) to the Last.fm, i.e. to the "About Me" box.
Thanks in advance!
how to check if a video is embeddable on a web page or not?
Thanks I have been looking all over for this!
Thanks! My same validator problem settled this way, too.
And various high value key infos collected from the comments, too.
Now 1000 generated pages of proprietery CMS (PERL generated) are zero error for "XHTML strict" - like ibm.com :-)
The most astonishing is:
This is now since 3 years here, and is to find via Google in a direct fast manner.
Of course, many complaints about the problem will have been addressed to youtub.com , in the meantime.
Why did the programmers there, with a multi-million annual budget, never settle this problem?
It is THEIR job, not ours, because THEY are paid for it, not we.
On the other hand, the importance of validation is low... The use of CAPITALS now is error, while it was standard 10 years ago...
When 10 years ago HTML tags / attributes were mainly programming language, they had to by upper case - should have been lower case, THEN.
Now that they mainly have a character of constants (due to crazy CSS conventions), they should NOW be in capitals - but now they have to be in lower case....
"Crazy conventions"? - It is a basic fault to let the user redefine the effect of elements of a supplied language. It is one of the worst possible violation of basic rules of systems using formalized languages...
HTML. XML , CSS, Javascript standards are bureaucratic horror stories, compared with the abstract logical perfection of PERL for scripting, Postscript /Adobe .pdf for style.
And validators tend to multiply one single true standard difference to 10 ... 100 ... or more "errors" or warnings...
Check the major German newspaper Frankfurter Allgemeine,
its site is: faz.net
Is it the Guiness Record Holder of the validation error count?
Over 5 000 errors and 300 warnings....
So faz.net is a good excuse for Web designers
when criticized by customers for the typical average of several 100 error messages of relatively long and complex web pages....
I would like to know if it's possible to use this embed code in combination with an insert of the video idea, this 11 digit code stacked in a mysql dbase. Is it possible and What would it look like?
Hey... Im so glad I found your site as I have been having problems with the different plugins Ive used to display youtube videos. Yours is the best method by far. Thanks!
Thats very awesome. Thank you so much for providing an alternative code for the YouTube.
thank u very much for ur post...
but could anyone help me embed the link of houndbite.com
they always break my html validation....
:(
happy to find this, saved me a lot of time searching aroudn the place
This code still works.
Many of my embedded videos in IE had become blank boxes!
I have just prepared a new page useing your code It seems to work in IE FF Chrome and Safari.
http://www.hibla.com/Youtube-movies.htm
This code worked made it so that everything on my page works correctly, except my Facebook application no longer appears in Explorer.
:(
You have no idea how happy I am to find this page. The Youtube tag in my bbcode parser was the only one left not producing valid XHTML 1.1 and now that's been solved, and in a way that works for IE users too :)
Thx :D Send YT an e-mail -,-
This is awesome! At work we need to use xhtml-strict that validates properly and flash was a pain in the ***. Now however, I successfully added a flash file to one of our sites :)
wonderful. thnx for ur nice work.
So very much help. I was killing myself trying to get this valid. Thanks for the code!
To enable the fullscreen button with this XHTML compliant method:
The ALONE is not sufficient - it won't show you the fullscreen button.
You must add ?fs=1 to the Video's URL to make the fullscreen button work.
The available parameters are documented here:
http://code.google.com/apis/youtube/player_parameters.html
Nice web.I have bought a pair of nike blazer shoes from a worldwide Zoom kobe v shopping website. Happy to share it with you sincerly.
Doesn't work in Google Chrome. It loads the whole movie (Even if you don't click on the play button) before loading the rest of the page, instead of streaming.
Thank you for the quick tutorial.
It validates! And it's much lighter code. Thanks mate!
Thank you! Worked great and the comments helped out, too.
Wonderful, thanks for the code, worked a treat on my site, now my blog software finally validates the same as the rest of my site.
@Don_Pedro Whilst I agree with your sentiment, the great thing about HTML and XHTML is that you can choose either or a mix of the two, following strict rules or transitional rules, so it's up to the designer to choose the one they are most proficient in at the time. And as for the uppercase, lowercase changes, there is plenty of software that can do that for you across thousands of HTML documents in seconds, so it's not really a problem.
I've have embedded a few videos in my website and have found them to be useful when trying to explain wesite concepts to customers.
Great, this code is valid @ validator.w3.org :)
Seems to work OK for me !
Thanks
Thank you so much for this post. It saved my ass.
I'd rather embed them using the xml wordpress plugin, but you are more technically advanced...
the xml template is not stable enough for these requirements.
I don't understand what is xml templates
Thank you very much
You really save me. I have tried it out and it is now working. Thanks so much for your help.
very useful tip for my videos
Thanks - very usefull!
Last time I embedded a player on my website. I made a small one and the quality of the audio was awefull. I changed the size to big and the audio was normal again. How is this possible?
@ Marcel. Yes, I don't know what that is with youtube, it really makes audio sound crappy.
You save my life!
Thanks for sharing this code
Is work for me!
Sorry my bad english!
Is there a way to modify the new YouTube code to eliminate or shrink the css and js files? Combined they are a whopping 350K!
Thanks for sharing...
Brilliant job! The comprehensive data given was very helpful. I am hoping that you continue the excellent job done.
best site for sri lanka
Thank You! Your example helped me out when I was without a clue.
Thanks again...
Post Comments
If you feel like commenting on the above item, use the form below. Your email address will be used for personal contact reasons only, and will not be shown on this website.
height and width attributes are prefectly fine in the object element, even for XHTML 1.1, see http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_objectmodule
So one should instead write the following:
<object type="application/x-shockwave-flash" width="425" height="350" data="http://www.youtube.com/v/7_6B6vwE83U"><param name="movie" value="http://www.youtube.com/v/7_6B6vwE83U" /></object>
Permalink