HTML YouTube Videos
The easiest way to play videos in HTML, is to use YouTube.
Struggling with Video Formats?
Different versions of different browsers support different video formats.
Earlier in this tutorial, you have seen that you might have to convert your videos to different video formats to make them play in all browsers.
Converting videos to different format can be difficult and time consuming.
An easier solution might be to let YouTube play the videos in your web page.
YouTube Video Id
YouTube will display an id (like XGSy3_Czz8k), when you save (or play) a video.
You can use this id, and refer to your video in HTML.
Playing a YouTube Video in HTML
To play your video on a web page, do the following:
- Upload the video to YouTube
- Take a note of the video id
- Define an <iframe> element in your web page
- Let the src attribute point to the video URL
- Use the width and height attributes to specify the dimension of the player
- Add any other parameters to the URL
Example - Using iFrame (the recommended method)
Value 0: The player controls are always visible.
Value 1: The player controls hides automatically when the video plays.
Value 2 (default): If the player has 16:9 or 4:3 ratio, same as 1, otherwise same as 0.
Value 0 (default): The video will not play automatically when the player loads.
Value 1: The video will play automatically when the player loads.
Value 0: Player controls does not display. The video loads immediately.
Value 1 (default): Player controls display. The video loads immediately.
Value 2: Player controls display, but the video does not load before the user initiates playback.
Value 0 (default): The video will play only once.
Value 1: The video will loop (forever).
A comma separated list of videos to play (in addition to the original URL).
YouTube <object> Embeds
YouTube <object> embeds were deprecated from January 2015.
You should migrate your applications to use <iframe> embeds.
Example - Using <object> (deprecated)
Example - Using <embed> (deprecated)