Here is some good news for YouTube fanboys, now you can embed YouTube videos using the new HTML5 embed code. The YouTube api blog recently announced that the team is experimenting with a new embed code that uses the iframe tag to switch between the flash and HTML5 interface.
YouTube added support for HTML5 earlier this year, followed by another popular video sharing site – Vimeo. The HTML5 video playback was limited to only a few browsers e.g Google Chrome, Safari and users were not given any embed code for the uploaded videos.
With the new iframe tag embedded in your website, the code will automatically detect whether you are using a browser that supports HTML5 or not.
The iframe code for embedding YouTube videos is as follows, simply copy the Video ID and replace in the code below:
<iframe type=”text/html” width=”640″ height=”385″ src=”http://www.youtube.com/embed/VIDEO_ID” frameborder=”0″>
Here is an example video embedded using the new HTML5 embed code:
Users will be able to view the embedded video in both Flash and HTML5 players, this depends on their viewing environment and browser preferences. You can find a complete list of HTML5 video players at this page
Please note that those videos which contain inline advertisements will be shown using Flash because HTML5 can not play the videos containing advertisements. The advantage of the new HTML5 embed code is that it will allow embed codes to work on various mobile devices, which use a built in player instead of either Flash or HTML5.
The new embed code is just a testing feature, more improvements are on the way. [ via YouTube API blog ]