Inclusion of YouTube Videos in HTML Pages

May 21, 2008 17:25 GMT  ·  By

Video clips are maybe the most searched Internet resource because they contain information having a high degree of accessibility as compared to classic static images or text. If you want to include and display video content in web pages, various alternatives are available.

There is the possibility to embed in HTML web pages your own video files or others having sharing rights over the Internet. Many of video sharing or social networking websites provide the code that must be included into web pages in order to automatically display a certain video file without the need to be on your web server.

In case of YouTube videos, the code provided for inclusion contains the embed directive, but this HTML tag will include a non standard object in document according to XHTML validation rules. The inclusion code provided for every YouTube video can be used in its actual form, but it will not be valid from the XHTML standards point of view.

The next YouTube video inclusion code example shows the correct (valid) XHTML variant:

code
data="http://www.youtube.com/v/identifier">

In the previous code example, the embed tag does not appear anymore. The text "identifier" must be replaced with a real YouTube video identifier (the combination formed by letters and numbers situated at the end of a link pointing to a certain video, like Iv7WYMtQWgg) or just simply change the entire link http://www.youtube.com/v/identifier with your own.

There are available many code generators which output valid XHTML code for embedding YouTube videos in web pages if you do not want to write the code manually. A valid YouTube video link must be provided and the resulted code can be directly copied and pasted into the desired document.

Generally, in order to have valid XHTML code, it is recommended to include multimedia files in your web pages by using the object tag without embed, as shown in this article.