Dexterity Unlimited presents articles about web design and web site architecture.

Dexterity Unlimited – Articles » Blog Archive » Get rid of those YouTube EMBED tags

Get rid of those YouTube EMBED tags

Unfortunately, there is not a good way to explain this problem without having this page generate an error in the W3C HTML validator. If you are a web standards advocate, as I am, you realize the distaste of purposefully creating a page that does not validate. Though this page is not valid XHTML, I present an evidence-based, cross-browser compatible method for embedding YouTube videos in this article.

Danger! Non-valid XHTML ahead!

I recently made a short video and uploaded it to YouTube for all to see. The video was made using GtkRecordMyDesktop on my PC, which is running Ubuntu Linux 8.04 with Compiz desktop effects enabled.

YouTube video with EMBED tag

The problem with YouTube is in the way that they have you embed the videos within a web page. This video is placed into the page using their default HTML code. The problem with this code is that it uses the EMBED tag. Why is this a bad thing? Well, I guess it’s because that tag is not valid for XHTML. The OBJECT tag is used to place multimedia objects within a web page when you are using XHTML. The EMBED tag was used in HTML 4.01, but has been deprecated in later revisions to the standards.

YouTube does use the OBJECT tag, but contained within that tag is an EMBED tag, invalidating the XHTML. Here is the standard code given by YouTube:

<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/pV4n1UiyRKo&amp;hl=en&amp;fs=1"></param>
<param name="allowFullScreen" value="true"></param>
<embed src="http://www.youtube.com/v/pV4n1UiyRKo&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" width="425" height="344"></embed>
</object>

And here is the resulting video within the page:

YouTube video with OBJECT tag

The code which I have used below to put the video into the page is slightly different, in that it does not use the EMBED tag. It eliminates the EMBED by moving the required attributes to the OBJECT tag. One attribute, SRC, must be replaced by the DATA attribute containing the same information. The valid XHTML used on this page for the second embedded video is this:

<object width="425" height="344" type="application/x-shockwave-flash" data="http://www.youtube.com/v/pV4n1UiyRKo&amp;hl=en&amp;fs=1">
<param name="movie" value="http://www.youtube.com/v/pV4n1UiyRKo&amp;hl=en&amp;fs=1" />
<param name="allowFullScreen" value="true" />
</object>

And the result of using this code looks like this:

Attention! Keep in mind that the code which YouTube gives at the end of the video to use to embed the video into another page is their original, non-valid code.

Which works best? After testing in various browsers on differing operating systems, both are just as functional, but only the modified code validates as proper XHTML. As an added bonus, the valid XHTML uses fewer bytes of space in the file. Why not make your embedded YouTube videos valid too?


Danger sign image courtesy takomabibelot by Attribution License.

Bookmark and Share

29 Responses to “Get rid of those YouTube EMBED tags”

  1. YouTube embed video code sucks! | Forums Blog Says:

    [...] Get rid of those YouTube EMBED tags | Dexterity Unlimited – Articles [...]

  2. Max Design - standards based web design, development and training » Some links for light reading (8/10/08) Says:

    [...] Get rid of those YouTube EMBED tags [...]

  3. Mel Pedley Says:

    I agree completely with your observation that EMBED is not part of either the HTML 4.01 or XHTML 1.0 standard. However (and as far as I am aware), user testing has shown that EMBED is currently the most accessible way of presenting certain multimedia objects – including videos. as such, I believe its usage can be considered if it is in the best interest of accessibility or usability. YouTube isn’t, itself, the best example of presenting videos in an accessible manner but, outside of YouTube, I think developers need to be aware that, in this particular situation, following standards blindly may not be best option.

    Have you tested your solution for access via keyboard? Or screen reader software?

    Just a thought…

  4. Dave Says:

    So what?

    Who uses XHTML anyway? EMBED is valid in HTML, and will continue to be valid for a very long time.

  5. Dan Johnson Says:

    Dave said:

    So what?

    Who uses XHTML anyway? EMBED is valid in HTML, and will continue to be valid for a very long time.

    Actually, the EMBED tag has never been a part of the HTML specifications, whether HTML 4.01 or XHTML. It is proposed as part of the HTML 5 specs, but I don’t even want to think about getting into that mess.

  6. Dan Johnson Says:

    Mel:
    Great questions regarding the accessibility of the multimedia objects. I’ve found several resources for information about this, but most of it seems to be at least a couple years old. One of the better is the cached version of a Macromedia Accessibility Blog which tests several embedded object techniques on a variety of browsers (including Firefox 1.0.4, JAWS 6.20.065, etc.). Perhaps this issue needs to be revisited with additional testing accross platforms/browsers/techniques. There is a good article on Accessible Flash techniques at WebAIM.
    What about the accessibility of YouTube’s Flash object itself? Posting cross-site objects can be very problematic for accessibility. I think hosting the video on your own site gives you the most control, but how many of us can afford the bandwidth associated with that?

  7. Andy Beard Says:

    Have you tested the valid code with various feed readers and additional sites such as Myspace, forums etc?

  8. Dan Johnson Says:

    Andy Beard said:

    Have you tested the valid code with various feed readers and additional sites such as Myspace, forums etc?

    Do you mean displaying the video within the feed reader? I suppose it depends on the multimedia functions built into the reader. I’m using Opera for reading my feeds, so there’s no problem there. I think perhaps we should test this.
    The code was a bit difficult to get to render properly in WordPress: I ended up making the post nearly all one single line of text in order to get the formatting to stay the way I wanted.
    Myspace videos seem to use nearly the same code in their videos. I haven’t tested one yet.

  9. Increase Youtube Views Says:

    TO be very true, A large part of our sites is not valid and up to mark according Xhtml. I have to go through the similar situation regarding meta tags of a site and owner of the site was using everything invalid. It is very difficult to convince someone that he/she is not using the right code or stuff according to standards. Anyhow thanks for sharing the tip.

  10. Kim Says:

    I used your code on a bunch of videos on my site. I added rel=o at the end of the line, for instance, http://www.youtube.com/v/XevObuXbOMg&hl=en&fs=1&rel=0.

    Usually when you add this it stops you tube displaying a slide show of other related videos (just get a replay button)

    When I did it with your code it made it much worse, now I get a search box, the embed code, the url as well as the wretched slide show.

    Any suggestions before I delete the lot and go back to non standard tags?

  11. Dan Johnson Says:

    Kim said:

    Any suggestions before I delete the lot and go back to non standard tags?

    This is an interesting problem. The YouTube Embedded Player Parameters seem like a good place to start. It isn’t clear to me yet whether YouTube is pulling the parameters from the full URL provided in the movie parameter, or from the data attribute in the object tag.

    Perhaps a good way to try this out would be to leave off everything after the question mark in the URLs, and provide the parameters you want in the param tags within the object container, like this:

    <param name="rel" value=”false” />

    YouTube indicates using both of these techniques at the same time, so adding the rel=0 to the URL and providing the param tag should solve your immediate problem. Please let me know if this works. It’s interesting to see what we are or are not able to do with YouTube.

    On a side note, I’ve also experimented with Flowplayer, an embedded flash video player that allows you to host your own FLV videos on your site and display them as you wish. This might be a good alternative if you don’t have a problem with the amount of bandwidth you could use, or you have videos that you for one reason or another can’t have on YouTube.

  12. Dan Johnson Says:

    Increase YouTube Views said:

    It is very difficult to convince someone that he/she is not using the right code or stuff according to standards.

    Yes, I’ve definitely found this to be difficult. Fortunately, things have been changing. Unfortunatly, the changes are very slow.

    One change that I was very glad to see was the adoption of the Illinois Information Technology Accessibility Act (IITAA). This law requires state agencies and universities to ensure that their web sites, systems, and other information technologies are accessible to people with disabilities. In the state’s guidelines for web sites’ compliance with this law is a section that I truly appreciate:

    1. Coding
    1.1 – Use valid, standard web programming code.
    What: The World Wide Web Consortium (W3C) sets and publishes standards for web programming languages including HyperText Markup Language (HTML/XHTML), and Cascading Style Sheets (CSS). Programming code is considered “valid” when it follows the rules and conventions specified in the published standards.

    Why: Valid code is the foundation for accessibility. Screen readers and other assistive technologies most reliably interpret and interact with web pages that are built using valid, standard code.

    How: For web pages, indicate the programming language you are using by starting your code with a standard document type declaration, such as:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    See the full list of W3C Recommended Document Type Declarations (http://www.w3.org/QA/2002/04/valid-dtd-list.html).
    Use the W3C HTML Validation Service (http://validator.w3.org) to check your code.

    Ref: WCAG 3.2, 11.1, 11.2

  13. Svet and Kyle Keeton Says:

    Thank you for telling about Flowplayer, I was looking for such service for a long time!

    One more problem with YouTube is that they force people to delete their good videos…

  14. Latterkursus peter Says:

    Maybe it is just me, but if both tags works equally well, what is the point of changing it ?

  15. Anonymous Says:

    Peter, I think you should read the post two before yours. It could also be particularly important if you are promoting yourself as delivering valid code BUT because of youtube you actually aren’t.

    Also I found this page very handy when the W3C Validator wouldn’t validate my page in HTML 4.01 Trans.
    Thanks

  16. Maria Says:

    Why do the examples look exactly same to me? I don’t think thats a big problem. Because websites should be designed for humans instead of robots, spiders and engines. Keep this in mind next time.

  17. Dan Johnson Says:

    Hi Maria,
    As Anonymous mentioned above, this is important in order to deliver code that meets W3C standards. If you deliver your pages as XHTML, YouTube’s code does not meet those standards.

    Yes, the functionality of a web page should be designed for human beings. But the code behind that functionality should be (in many people’s opinion) presented in a manner that meets current standards. Yes, the two examples look the same, and currently should operate the same in the current generation of web browsers.

    The embed tag has never been a part of the HTML standards, although it is proposed for HTML 5. Accordingly, a future web browser that supports XHTML 1.0 standards fully does not have to understand what that tag is, and can ignore it completely if it is presented in a page declared to be XHTML 1.0. The object tag is the standards-compliant tag used to place media not covered by other tags within a web page.

  18. convert videos to mp3s Says:

    I am a newbie as far as html code is concerned. Will this embedding of you tube video expose my site to any security risk?

  19. Dan Johnson Says:

    The methods used to place the YouTube content on a page on your own site should not expose your site to any particular risks. Basically you are telling the browser to place a block of special content in that position and to grab that content from a particular place on YouTube’s servers.

    Granted, it might be possible to do some nasty browser manipulation in this way if, in fact, YouTube were not an honorable company allowing people to specifically do just that. But considering their track record thus far, I’m sure YouTube is a very safe source for multimedia content.

  20. Tom Says:

    I also use parameter &ap=%2526fmt%3D18 to have google’s high quality video embedded instead of default quality

  21. Lydbog Morten Says:

    @Tom
    Thanks for the heads up on the google video. I changed it on both the sites where I have video, it definately makes a difference.

  22. ancy backgammon Says:

    Perhaps a good way to try this out would be to leave off everything after the question mark in the URLs, and provide the parameters you want in the param tags within the object container the functionality of a web page should be designed for human beings. But the code behind that functionality should be (in many people’s opinion) presented in a manner that meets current standards..Really i am impressed from this post….the person who create this post it was a great human..thanks for shared this with us.i found this informative and interesting blog so i think so its very useful and knowledge able.I would like to thank you for the efforts you have made in writing this article.

  23. Casino gratis spielen Says:

    It is very difficult to convince someone that he/she is not using the right code or stuff according to standards.It could also be particularly important if you are promoting yourself as delivering valid code BUT because of you tube you actually aren’t. Basically you are telling the browser to place a block of special content in that position and to grab that content from a particular place on You Tube servers.

  24. Tom Gurney @ MP3 Itunes Downloads Store Says:

    Why was the embed tag deprecated? Personally, i try to make things compliant for the purposes of page design (ie easier to bug check) but i dont get too held up on making sure its compliant 100%. I always go for transitional xhtml and just make sure its consistent cross-browser. The codes needed to publish swfs are now more complicated (but still qute easy!) with these changes, so i assume there was a good reason for taking embed from xhtml.
    I do respect you for targeting 100% compliance, but i just dont find it realistic on the sites that i work on, with 3rd party editors, etc…

  25. eibmoz Says:

    Thanks for hosting the information and all the posts on this topic. I plan to embed my youtube videos on website and will try the different codes.

  26. Andrew Croft Says:

    Embed never has been part of HTML 4.01 or XHTML!!

  27. forums Says:

    Thank you very much

    I am looking for these codes

    realy thank you

  28. John Cook Says:

    This has really helped in stopped people stealing my videos! Thanks

  29. Emrah Ba?kaya Says:

    There’s another reason not to use embed: Firefox has a bug that causes the embedded object to show even in overflow clipped areas, that is, it is still visible in a non-viewable part of an overflowed element. Thanks for the tip!

Leave a Reply