How to embed YouTube and Google Video without breaking validation!

Posted in Blogging on Sep 10, 2006

So, here’s the code for either one:

<object type="application/x-shockwave-flash" data="[INSERT VIDEO URL FROM EMBED CODE PROVIDED HERE]” width=”400″ height=”326″><param name=”movie” value=”[INSERT VIDEO URL FROM EMBED CODE PROVIDED HERE]” /><param name=”FlashVars” value=”playerMode=embedded” /></object>

Took a while to figure out, but it works. I originally tried the code mentioned in this article, but it kept breaking my site, so I trimmed it all down to the bare essentials. This works for me and my template. Let me know if it does / doesn’t work for yours in the comments. w00t!

UPDATE: Great post from Ryan over at Hapless band of staff and regulars, where he tweaks my code slightly to avoid YouTube upscaling of the video. Check it out.


Recommend on Mahalo

Trackback URI | Comments RSS

80 Responses to “ How to embed YouTube and Google Video without breaking validation! ”

  1. # 1 Blargg Says:

    Works great. Thanks.

  2. # 2 Virtual Magic Says:

    http://www.virtualvideomap.com

  3. # 3 tech.no.philia | random musings, but mostly on technology » Blog Archive » The Two Easiest Ways to Embed Videos in WordPress Says:

    [...] If you are for some reasons against installing a plugin, and yet want to embed YouTube and Google Video in your blog, you can try this following code as recommended by C.K. Sample III in his blog: [...]

  4. # 4 Random Insights » Blog Archive » links for 2006-09-23 Says:

    [...] Sample the Web — How to embed YouTube and Google Video without breaking validation! So, here’s the code for either one: (tags: GoogleVideo Wordpress XHTML embed YouTube standards Internet web2.0) [...]

  5. # 5 Amy Stephen Says:

    Your work was a GREAT help for me today and stopped me from stepping in front of a train. Perhaps you could write for A List Apart. How can they make it so complicated — and yet, still not work!

    Honestly, thanks a ton, dude! :)

  6. # 6 Embedding Video without XHTML Transitional Validation Errors at Amy Stephen Says:

    [...] SampletheWeb is the one who gave me the answer - simply. I thank you. You rock! [...]

  7. # 7 Hilde Says:

    Great! Thanks a lot!

  8. # 8 Murdoc Online Says:

    Murdoc’s FurnaceCam…

    How people were able to survive before high-speed internet, Murdoc can’t figure…….

  9. # 9 Michiblogger Says:

    Valid YouTube Format…

    EMBEDDED YOUTUBE PLAYERS built the easy way using the handy code on the YouTube are actually invalid HTML. If you care about building valid web pages, try this solution. Worked great for the Patrick Stewart video player below. Also, MichiBlogger……

  10. # 10 Nix Says:

    Thank you very much!

  11. # 11 Ferguson Says:

    I’m new about this “blog-video-stuff”.
    An example? I really don’t understand how to put this in the Wordpress template.

    Thank you and excuse my english (really sucks!).

  12. # 12 After the Net » Blog Archive » links for 2006-12-23 Says:

    [...] How to embed YouTube and Google Video without breaking validation! (tags: blogging google howto videos W3C web2.0 webdev website wordpress xhtml youtube) [...]

  13. # 13 meeciteewurkor Says:

    groovy. Killed 8 validation errors I was trying to get rid of.

  14. # 14 TBL Says:

    Is there anyway to get this code to work with firefox too? It works great with IE but does not show up with FF (at least not on my machines)

    thanks

  15. # 15 motherduce Says:

    Yup, not working for me in FF either. Any ideas?

  16. # 16 Al Says:

    Works fine for me in FF 1.5 and FF 2.0 - Embedding Google Video clip. Using Flash Player 9.
    Al

  17. # 17 eternos.org Says:

    YouTube vs XHTML…

    Seria lógico pensar que um site tão famoso como o YouTube, fosse um exemplo de perfeição e cuidado na estruturação no código do seu webite. Mas não é…
    Tudo bem, cada qual sabe de si, e compreendo que num site com aquela…

  18. # 18 L. Gariépy Says:

    Great! you solved my problem, and it does not work only for Netscape but for IE too!
    Thanks!

  19. # 19 arakno Says:

    Dude, you saved my blog from breaking apart! :’)
    Thanks a lot!!

  20. # 20 arakno Says:

    eskeci de deixar o link pro meu blog…

  21. # 21 Shaina Says:

    This page will help you to convert youtube’s code into a valid XHTML.

    http://www.gl3nnx.net/valid-xhtml-youtube.php

    No Sweat! instant valid XHTML!

  22. # 22 Adding Youtube or Google Video to Blogs at Bee Hive Says:

    [...] Success!!! I love that word, after attempting for a few days to get video’s working on the blog I finally found the information that I needed on a site called Sample the Web. [...]

  23. # 23 tenthofjune Says:

    Embedding a Google or Youtube Video without breaking validation…

    If you use the code on Google Video or Youtube to embed a video on your website, they give you the now defunct embed tag which breaks the HTML validation. You can however get around this using the method on CK Samples blog.

    ……

  24. # 24 TenthOfMarch Says:

    Just want to inform that the codings provided by c.k. works for metacafe videos as well. Just replace the embedded video’s url into his codings. I haven’t tried it with other video sites, but I think it should work for those as well. Thanks for the codings!

  25. # 25 TenthOfMarch.com » Blog Archive » Sucker For Perfection Says:

    [...] glass? I wasn’t going to give up that easily. I went to google for a solution and found C.K. Sample III. Thanks to him, my site is 100% valid once [...]

  26. # 26 TenthOfMarch.com » Blog Archive » Tutorial: How to embed flash video in your blog without breaking validation Says:

    [...] to that problem. This tutorial is possible thanks to C.K. Sample III who has provided a nicely modified code to replace the default codes given by those [...]

  27. # 27 Sample the Web — Someone wrote up a step by step tutorial… Says:

    [...] of my how to embed Google Video / YouTube without breaking validation post. Check it out here. Share and Enjoy (Netscape is at the top of the post):These icons link to [...]

  28. # 28 vijaianand Says:

    I still don’t see my embedded youtube video in my blog. I see it my other machines and not in my laptop. I reinstalled Flash plugin and still not working.. Help me here..

    Thanks
    VIJAI

  29. # 29 Tyler Regas Says:

    Works great. Gracias!

  30. # 30 dna Says:

    cool stuff, works like a charm. thanks for sharing.

    http://basilar.net

  31. # 31 haha Says:

  32. # 32 Guillaume Sahut Says:

    F*ckin Hell! Yur a GOD!!!
    I’m tryin to find a way to display these goddam vidz without breaking the W3C Validation for hours…

    ThanXX A LAAAAAATTT ^^

  33. # 33 Блокнот » как красиво встроить YouTube видео в сайт Says:

    [...] Возможно, тип будет кому-то полезным. Оригинально взят здесь. [...]

  34. # 34 Vernon Says:

    Thanks, just used it for my site and it works great!

  35. # 35 Tom Cobbaert .eu » Validation Says:

    [...] er op aan te komen te kiezen tussen Europa en W3C, maar toen kwam de deus ex machina: “How te embed YouTube and Google Video without breaking validation“. Deze mens zorgde ervoor dat iedere Zeldman-getrouwe nu zonder enig gewetensbezwaar filmpjes [...]

  36. # 36 glenneroo Says:

    hmm well got rid of all the validation errors, but all i see is a white box which isn’t clickable or anything. I’m using Firefox 2.0.0.3

  37. # 37 c.k. Says:

    Make sure you use the URL in YouTube’s embed code, NOT the videos URL.

  38. # 38 glenneroo Says:

    ah ok well the link someone above posted here works:
    http://www.gl3nnx.net/valid-xhtml-youtube.php

    but it leaves a white border on top/bottom and to the right one pixel, so change width to 424px and height to 336px

  39. # 39 Nida in the parra » Blog Archive » Validando el código de YouTube Says:

    [...] Hoy he “Googleado” un poco y he encontrado una solución que a mí al menos me ha funcionado (How to embed YouTube and Google Video without breaking validation!). [...]

  40. # 40 drekwon Says:

    Super! I had the same problem but that did the work!

    Thanx man

  41. # 41 Trimidium Says:

    What blows my mind is the fact that all of those services offer embeding as a service, but don’t make it valid code when they easilly can.

    Thanks,
    http://www.thesmartass.info

  42. # 42 JoeLiTo Says:

    Thanks for that. Your method validates in XHTML 1.1 and that’s the one I needed.

  43. # 43 Wes Linda Says:

    Great tip, works cleanly, easy to understand, and I agree with many of the comments above. Why does everyone have to make it so hard?

  44. # 44 Jesus Says:

    Thank u very much guy!

  45. # 45 Christopher Davis Says:

    Thank you for this code! I wonder why Google doesn’t use it?
    One thing I had to do however…
    I was getting 5 validation errors when I first used your code. When I took out the &hl=en from the end of the docId code, it passes completely…

    I suppose that stands for home language = English ? probably used by Google to filter your language results but not necessary to play when embedding.

    Chris Davis
    http://www.chrisdavistech.com

  46. # 46 deviantz Says:

    Nice, Thank you!

    Deviantz - http://www.iCzalazar.com

  47. # 47 asdsd Says:

  48. # 48 asdsd Says:

    http://www.youtube.com/v/HpwtQiHZI2E

  49. # 49 billc Says:

    Bummer that the video controls don’t work though. Would be nice to be able to pause.

  50. # 50 Capitano Uncino » Archivio Blog » Validare il codice di YouTube e simili Says:

    [...] li si vada a prendere?Ebbene, la soluzione forse migliore è quella suggerita in questa pagina di Sample The Web.In pratica, si procede in questo modo: invece di inserire nel vostro post il codice fornitovi dal [...]

  51. # 51 Jake Kasprzak Online › Link to YouTube Video Pages from Embedded YouTube Videos Says:

    [...] always get embedded in web pages the way it is suggested on the pages for YouTube videos. In fact, if you click here or here you’ll see that the use of the <embed> tag may not always be used in embedding [...]

  52. # 52 XHtml Doğrulamasından Geçebilen Youtube Embed Kodu | Açık kaynak ve kişisel tecrübeler Says:

    [...] bakın! Eh ne yapalım iş başa düştü o zaman doğru kodu arayıp bulmamız lazım. İşte şurada tam aradığımız şeyi buluyoruz. peki kodumuz nasıl bir şeye [...]

  53. # 53 lee Says:

    hey, this works great, thanks for helping the web with your work

  54. # 54 YouTube Kodları XHTML Doğrulamasından Geçsin - Teknobaz Says:

    [...] [geldik.biz] XHtml Doğrulamasından Geçebilen Youtube Embed Kodu [Sample the Web] How to embed YouTube and Google Video without breaking validation! [...]

  55. # 55 kelvin Says:

    Great, it’s what I looking for,Thx

    http://www.digitalframe0.com

  56. # 56 Embeding YouTube and Google Video without breaking validation « The Official MartinZ Blog Says:

    [...] Mon, 19 Nov 07, 12:27 am Try this out from Sample the Web. [...]

  57. # 57 How to embed Blip.tv videos without breaking validation! Says:

    [...] Related: How to Embed YouTube and Google Video without Breaking Validation! [...]

  58. # 58 Lolita Loco Says:

    Big thank you! =)

  59. # 59 Make It Up As You Go » Blog Archive » How to Embed YouTube and Google Video with Valid Code Says:

    [...] Sample the Web has an easy method for embedding YouTube or Google Videos without breaking validation. (via Design Canopy) [...]

  60. # 60 Jazzo Says:

    Thank you, this worked great. I also used it to help me embed myspace videoa without breaking validation:

    Hope this helps too :)

  61. # 61 Jazzo Says:

  62. # 62 YouTube & WordPress ist auch eine Zumutung at blog.gauner.org Says:

    [...] Glück gibts hier einen Hinweis wie man das Layout rettet. <object type=”application/x-shockwave-flash” [...]

  63. # 63 YouTube Enabled? : a8le.com Says:

    [...] thoughts using YouTube videos.  The code wasn’t hard and thanks to C.K. Sample’s blog (here), it was even [...]

  64. # 64 Eric Amundson Says:

    Worked perfectly, thanks!

  65. # 65 Where does my time go? | lifepassedby.com | Starting again Says:

    [...] anyone else has had this same issue and whether or not they were able to fix it. With the help of this site I found exactly what I was looking for and was able to fix the validation error. I was able to [...]

  66. # 66 How to embed YouTube videos directly into your webpage without breaking validation Says:

    [...] thanks to C.K. Sample III [...]

  67. # 67 steveking Says:

    YouTubeRobot.com today announces YouTube Robot 2.0, a tool that enables you to download video from YouTube.com onto your PC, convert it to various formats to watch it when you are on the road on mobile devices like mobile phone, iPod, iPhone, Pocket PC, PSP, or Zune.

    YouTube Robot allows you to search for videos using keywords or browse video by category, author, channel, language, tags, etc. When you find something noteworthy, you can preview the video right in YouTube Robot and then download it onto the hard disk drive. The speed, at which you will be downloading, is very high: up to 5 times faster than other software when you download a single file and up to 4 times faster when you download multiple files at a time.

    Manual download is not the only option with YouTube Robot. You may as well schedule the download and conversion tasks to be executed automatically, even when you are not around. Downloading is followed by conversion to the format of your choice and uploading videos to a mobile device (if needed). For example, you can plug in iPod, select the video, go to bed, and when you wake up next morning, your iPod will be ready to play new YouTube videos.

    Product page: http://www.youtuberobot.com
    Direct download link: http://www.youtuberobot.com/download/utuberobot.exe
    Company web-site: http://www.youtuberobot.com
    E-mail: support@youtuberobot.com

  68. # 68 Dizi Says:

    i was looking for this thank you.

  69. # 69 Firma Rehberi Says:

    great codes thanks

  70. # 70 jane doe Says:

    found your blog which definitely helped me in getting code to validate (thanks!) … one thing to add, for embedding hulu videos where specific clips are chosen from a longer video there: in the code hulu will give, part of it will have something like “st=400&et=550″ (st being “start time” and et being “end time” — numbers here are just examples). With your validating code, you’d take the start/end code and add it to this part:

    <param name="FlashVars" value="playerMode=embedded" />

    so that it would look similar to this:

    <param name="FlashVars" value="st=1022&et=1157&playerMode=embedded" />

    (Again, the numbers are examples only; one would use whatever numbers are in the embed code hulu gives for the particular clip chosen.)

  71. # 71 jane doe Says:

    PS of course use (without spaces):

    & amp;

    in place of just & in the code … that part didn’t come through right in the example.

  72. # 72 state shirt Says:

    hey thanks a bunch. this is exactly what I was looking for. now my site doesn’t break IE.

  73. # 73 James Young Says:

    Works here. Thank you.

  74. # 74 James Young Says:

    Wordpress users: this is a plugin that embeds all of the current media today without breaking validation!
    http://wordpress.org/extend/plugins/video-embedder/#post-5127

  75. # 75 youtube Says:

    thanks…

  76. # 76 Embedding YouTube and Google Videos Without Breaking Validation Revisited | Sample the Web Says:

    [...] of the most popular posts I’ve ever done is my How to Embed YouTube and Google Video Without Breaking Validation post, and this morning, I spotted a new, helpful inbound link to it: YouTube and embedding [...]

  77. # 77 dizi izle Says:

    thank you man

  78. # 78 PhotoFiltre Studio Says:

    hey, great work, thanks

  79. # 79 Rob C Says:

    Thanks for the quick fix.

  80. # 80 çocuk oyunları Says:

    thanks for fix

Leave a Reply


  • You Avatar
    i am a yeti