Embedding Youtube videos is a very popular practice by many bloggers. What better way to share a video than by embedding it directly onto your post? The problem with doing this, however, is that Youtube does not provide an XHTML valid embed code. This leaves some bloggers (especially those that are tightwads about their site being valid) frustrated.
Don't fret, however, as I have the answer!
If you were to view my video about animating in Flash, you'd see that this is the code that Youtube suggests you simply paste into your article so you can embed it:
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/rIr5R3FNm0M&hl=en&fs=1"></param>
<param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/rIr5R3FNm0M&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed>
</object>The problem here is that Youtube is still using the old embed tag, which is no longer used in today's coding standards. You'd think a big site like Youtube could find the time to simply modify this tiny snippet of code and make an endless amount of people happy, right?
But no, they don't. If you want to embed this same video with valid XHTML, you have to do it yourself. Here's the valid way of accomplishing the same task as above:
<object type="application/x-shockwave-flash" width="425" height="344" data="http://www.youtube.com/v/rIr5R3FNm0M&hl=en&fs=1">
<param name="movie" value="http://www.youtube.com/v/rIr5R3FNm0M&hl=en&fs=1"></param>
<param name="wmode" value="transparent"></param>
</object>And there you have it, your valid code Youtube video is now embedded. Pat yourself on the back for keeping your standards high.
If you liked this post, stay updated. Follow me on Twitter or subscribe to our RSS Feed via email.
Post Tags: Saturday Snippets


I never really embed videos into my posts, but this is a cool code to use if I ever do.
Thanks