Overview
This document explains how to embed a YouTube player in your application and also defines the parameters that are available in the YouTube embedded player.
YouTube players can be embedded in a web page using either an <iframe>
tag or an <object>
tag. By appending parameters to the SWF or IFrame URL, you can customize the playback experience in your application. For example, you can automatically play videos using the autoplay
parameter or cause a video to play repeatedly using the loop
parameter. You can also enable the JavaScript API for the player with the enablejsapi
parameter.
This page currently defines all parameters supported in any YouTube embedded player. You can change the parameters listed by selecting a specific player from the pulldown menu next to the first paragraph in the Parameters section or by selecting Show all
in that menu to view all parameters.
Note: To allow room for critical player functionality, players must be at least 200px by 200px.
Embedding a YouTube player
Best practice: IFrame embeds are the recommended method for embedding a YouTube player because the IFrame will select the appropriate player based on the client’s capabilities and available YouTube file formats.
You can use any of the following methods to embed a YouTube player in your application and specify player parameters. Note that the instructions below demonstrate how to embed a player that loads a single video. The following section explains how to configure your player to load other types of content, such as playlists and search results.
-
IFrame embeds using
<iframe>
tagsDefine an
<iframe>
tag in your application in which thesrc
URL specifies the content that the player will load as well as any other player parameters you want to set. The<iframe>
tag’sheight
andwidth
parameters specify the dimensions of the player.If you are creating the
<iframe>
element yourself (rather than using the IFrame Player API to create it), you can append player parameters directly to the end of the URL. The URL has the following format:http://www.youtube.com/embed/VIDEO_ID
The
<iframe>
tag below would load a 640x390px player that would play the YouTube videou1zgFlCw8Aw
. Since the URL sets theautoplay
parameter to1
, the video would play automatically once the player has loaded.<iframe id="ytplayer" type="text/html" width="640" height="390" src="http://www.youtube.com/embed/u1zgFlCw8Aw?autoplay=1&origin=http://example.com" frameborder="0"/>
-
IFrame embeds using the IFrame Player API
Follow the IFrame Player API instructions to insert a video player in your web page or application after the Player API’s JavaScript code has loaded. The second parameter in the constructor for the video player is an object that specifies player options. Within that object, the
playerVars
property identifies player parameters.The HTML and JavaScript code below shows a simple example that inserts a YouTube player into the page element that has an
id
value ofytplayer
. TheonYouTubePlayerAPIReady()
function specified here is called automatically when the IFrame Player API code has loaded. This code does not define any player parameters and also does not define other event handlers.<div id="ytplayer"></div> <script> // Load the IFrame Player API code asynchronously. var tag = document.createElement('script'); tag.src = "https://www.youtube.com/player_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); // Replace the 'ytplayer' element with an <iframe> and // YouTube player after the API code downloads. var player; function onYouTubePlayerAPIReady() { player = new YT.Player('ytplayer', { height: '390', width: '640', videoId: 'u1zgFlCw8Aw' }); } </script>
-
AS3 (and AS2*) object embeds
* Note: The AS2 Player API is deprecated.
Object embeds use an
<object>
tag to specify the player’s dimensions and parameters. The sample code below demonstrates how to use an object embed to load an AS3 player that automatically plays the same video as the previous two examples.<object width="640" height="390"> <param name="movie" value="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&autoplay=1"></param> <param name="allowScriptAccess" value="always"></param> <embed src="https://www.youtube.com/v/u1zgFlCw8Aw?version=3&autoplay=1" type="application/x-shockwave-flash" allowscriptaccess="always" width="640" height="390"></embed> </object>
Selecting content to play
You can configure your embedded player to load a video, a playlist, a user’s uploaded videos, or search results for a particular query. However, options other than loading a single video are only supported in AS3 object embeds and in IFrame embeds that load the AS3 player. (IFrame embeds could also load the HTML5 player.)
The following list explains these options:
-
Loading a video
For an IFrame embed, the YouTube video ID for the video that you want to load is specified in the IFrame’s
src
URL. For an AS3 or AS2 object embed, the video ID is specified in the player’s SWF URL.IFrame embed: http://www.youtube.com/embed/VIDEO_ID Embedded AS3 player: http://www.youtube.com/v/VIDEO_ID?version=3 Chromeless AS3 player: http://www.youtube.com/apiplayer?video_id=VIDEO_ID&version=3
If you are using the YouTube Data API, you can programmatically construct these URLs by retrieving the
<yt:videoid>
tag value in an API entry and replacing theVIDEO_ID
text in the URLs above with that value. You should also confirm that the feed entry for the video contains a<media:content>
tag for which the value of theyt:format
attribute is5
. The absence of that tag indicates that the video owner has disabled embedding for the video.<entry> ... <media:group> <media:content url="http://www.youtube.com/v/VIDEO_ID?version=3" type="application/x-shockwave-flash" medium="video" isDefault="true" expression="full" duration="100" yt:format="5"/> ... <yt:videoid>VIDEO_ID</yt:videoid> </media:group> ... <entry>
-
Loading a playlist
Set the
listType
player parameter toplaylist
. In addition, set thelist
player parameter to the YouTube playlist ID that you want to load.http://www.youtube.com/embed?listType=playlist&list=PLAYLIST_ID
Note that you need to prepend the playlist ID with the letters
PL
as shown in the following example:http://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6
If you are using the YouTube Data API, you can programmatically construct these URLs by retrieving the
<yt:playlistId>
tag value in an API entry and replacing thePLAYLIST_ID
text in the URL above with that value. -
Loading a user’s uploaded videos
Set the
listType
player parameter touser_uploads
. In addition, set thelist
player parameter to the YouTube username whose uploaded videos you want to load.http://www.youtube.com/embed?listType=user_uploads&list=USERNAME
-
Loading search results for a specified query
Set the
listType
player parameter tosearch
. In addition, set thelist
player parameter to the query term for which you want the player to load search results.http://www.youtube.com/embed?listType=search&list=QUERY
Parameters
All of the following parameters are optional. The list shows parameters supported in any YouTube embedded player. If all players do not support a particular parameter, that parameter’s definition will identify the players that do support it. Note that these parameters are only officially supported by the embedded player, but a subset of them may also work with other players such as the playlist player.
Note: IFrame embeds can load either the HTML5 player or the AS3 player. Though some parameters are not supported in both players, an IFrame embed that loads the AS3 player will support all parameters that work with that player and ignore all other parameters. Similarly, an IFrame embed that loads the HTML5 player will support all parameters that work with that player while ignoring all other parameters.
For example, the HTML5 player does not currently support the cc_load_policy
parameter, but you can still specify that parameter when creating an IFrame embed. If the embed loads the AS3 player, the player will support the parameter, and if the embed loads the HTML5 player, the player will ignore it.
All YouTube player parameters
autohide
(supported players: AS3, AS2, HTML5)- Values:
2
(default),1
, and0
. This parameter indicates whether the video controls will automatically hide after a video begins playing. The default behavior (autohide=2
) is for the video progress bar to fade out while the player controls (play button, volume control, etc.) remain visible.- If this parameter is set to
1
, then the video progress bar and the player controls will slide out of view a couple of seconds after the video starts playing. They will only reappear if the user moves her mouse over the video player or presses a key on her keyboard. - If this parameter is set to
0
, the video progress bar and the video player controls will be visible throughout the video and in fullscreen.
- If this parameter is set to
autoplay
(supported players: AS3, AS2, HTML5)- Values:
0
or1
. Default is0
. Sets whether or not the initial video will autoplay when the player loads. cc_load_policy
(supported players: AS3, AS2)- Values:
1
. Default is based on user preference. Setting to1
will cause closed captions to be shown by default, even if the user has turned captions off. color
(supported players: AS3, HTML5)- This parameter specifies the color that will be used in the player’s video progress bar to highlight the amount of the video that the viewer has already seen. Valid parameter values are
red
andwhite
, and, by default, the player will use the color red in the video progress bar. See the YouTube API blog for more information about color options.Note: Setting the
color
parameter towhite
will disable themodestbranding
option. controls
(supported players: AS3, HTML5)- Values:
0
,1
, or2
. Default is1
. This parameter indicates whether the video player controls will display. For AS3 players, it also defines when the Flash player will load:controls=0
– Player controls do not display in the player. For AS3 players, the Flash player loads immediately.controls=1
– Player controls display in the player. For AS3 players, the Flash player loads immediately.controls=2
– Player controls display in the player. For AS3 players, the Flash player loads afer the user initiates the video playback.
Note: The parameter values
1
and2
are intended to provide an identical user experience, butcontrols=2
provides a performance improvement overcontrols=1
. Currently, the two values still produce some visual differences in the player, such as the video title’s font size. However, when the difference between the two values becomes completely transparent to the user, the default parameter value may change from1
to2
. disablekb
(supported players: AS3, AS2)- Values:
0
or1
. Default is0
. Setting to1
will disable the player keyboard controls. Keyboard controls are as follows:Spacebar: Play / Pause
Arrow Left: Jump back 10% in the current video
Arrow Right: Jump ahead 10% in the current video
Arrow Up: Volume up
Arrow Down: Volume Down
enablejsapi
(supported players: AS3, AS2, HTML5)- Values:
0
or1
. Default is0
. Setting this to1
will enable the Javascript API. For more information on the Javascript API and how to use it, see the JavaScript API documentation. end
(supported players: AS3)- Values: A positive integer. This parameter specifies the time, measured in seconds from the start of the video, when the player should stop playing the video. Note that the time is measured from the beginning of the video and not from either the value of the
start
player parameter or thestartSeconds
parameter, which is used in YouTube Player API functions for loading or queueing a video. fs
(supported players: AS3, AS2)- Values:
0
or1
. For the AS3 player, the default value is1
, which causes the fullscreen button to display. Setting this parameter to0
prevents the fullscreen button from displaying.In the AS2 player, the default value is
0
. Setting the value to1
enables the fullscreen button in the embedded player and does not affect the chromeless player. The fullscreen option will not work if you load the YouTube player into another SWF. Note that, for the AS2 player, you must include some extra arguments to your embed code for this to work. The bold text in the following example is required to enable fullscreen functionality:<object width="560" height="315"> <param name="movie" value="https://youtube.googleapis.com/v/u1zgFlCw8Aw?version=2&fs=1"</param> <param name="allowFullScreen" value="true"></param> <param name="allowScriptAccess" value="always"></param> <embed src="https://youtube.googleapis.com/v/u1zgFlCw8Aw?version=2&fs=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="560" height="315"> </embed> </object>
iv_load_policy
(supported players: AS3, AS2, HTML5)- Values:
1
or3
. Default is1
. Setting to1
will cause video annotations to be shown by default, whereas setting to3
will cause video annotation to not be shown by default. list
(supported players: AS3)- The
list
parameter, in conjunction with thelistType
parameter, identifies the content that will load in the player.- If the
listType
parameter value issearch
, then thelist
parameter value specifies the search query. - If the
listType
parameter value isuser_uploads
, then thelist
parameter value identifies the YouTube user whose uploaded videos will be loaded. - If the
listType
parameter value isplaylist
, then thelist
parameter value specifies a YouTube playlist ID. In the parameter value, you need to prepend the playlist ID with the lettersPL
as shown in the example below.http://www.youtube.com/embed?listType=playlist&list=PLC77007E23FF423C6
Note: If you specify values for the
list
andlistType
parameters, the IFrame embed URL does not need to specify a video ID. - If the
listType
(supported players: AS3)- The
listType
parameter, in conjunction with thelist
parameter, identifies the content that will load in the player. Valid parameter values areplaylist
,search
, anduser_uploads
.If you specify values for the
list
andlistType
parameters, the IFrame embed URL does not need to specify a video ID. loop
(supported players: AS3, HTML5)- Values:
0
or1
. Default is0
. In the case of a single video player, a setting of1
will cause the player to play the initial video again and again. In the case of a playlist player (or custom player), the player will play the entire playlist and then start again at the first video.Note: This parameter has limited support in the AS3 player and in IFrame embeds, which could load either the AS3 or HTML5 player. Currently, the
loop
parameter only works in the AS3 player when used in conjunction with theplaylist
parameter. To loop a single video, set theloop
parameter value to1
and set theplaylist
parameter value to the same video ID already specified in the Player API URL:http://www.youtube.com/v/VIDEO_ID?version=3&loop=1&playlist=VIDEO_ID
modestbranding
(supported players: AS3, HTML5)- This parameter lets you use a YouTube player that does not show a YouTube logo. Set the parameter value to
1
to prevent the YouTube logo from displaying in the control bar. Note that a smallYouTube
text label will still display in the upper-right corner of a paused video when the user’s mouse pointer hovers over the player. origin
(supported players: AS3, HTML5)- This parameter provides an extra security measure for the IFrame API and is only supported for IFrame embeds. If you are using the IFrame API, which means you are setting the
enablejsapi
parameter value to1
, you should always specify your domain as theorigin
parameter value. playerapiid
(supported players: AS3, AS2)- Value can be any alphanumeric string. This setting is used in conjunction with the JavaScript API. See the JavaScript API documentation for details.
playlist
(supported players: AS3, HTML5)- Value is a comma-separated list of video IDs to play. If you specify a value, the first video that plays will be the
VIDEO_ID
specified in the URL path, and the videos specified in theplaylist
parameter will play thereafter. rel
(supported players: AS3, AS2, HTML5)- Values:
0
or1
. Default is1
. This parameter indicates whether the player should show related videos when playback of the initial video ends. showinfo
(supported players: AS3, AS2, HTML5)- Values:
0
or1
. The parameter’s default value is1
. If you set the parameter value to0
, then the player will not display information like the video title and uploader before the video starts playing.If the player is loading a playlist, and you explicitly set the parameter value to
1
, then, upon loading, the player will also display thumbnail images for the videos in the playlist. Note that this functionality is only supported for the AS3 player since that is the only player that can load a playlist. start
(supported players: AS3, AS2, HTML5)- Values: A positive integer. This parameter causes the player to begin playing the video at the given number of seconds from the start of the video. Note that similar to the
seekTo
function, the player will look for the closest keyframe to the time you specify. This means sometimes the play head may seek to just before the requested time, usually no more than ~2 seconds. theme
(supported players: AS3, AS2, HTML5)- This parameter indicates whether the embedded player will display player controls (like a ‘play’ button or volume control) within a dark or light control bar. Valid parameter values are
dark
andlight
, and, by default, the player will display player controls using thedark
theme. See the YouTube API blog for more information about the dark and light themes.
Deprecated parameters only used in the AS2 Player API
The following parameters are only supported for the AS2 Player API, which has been deprecated:
border
(supported players: AS2)0
or 1
. Default is 0
. Setting to 1
enables a border around the entire video player. The border’s primary color can be set via the color1
parameter, and a secondary color can be set by the color2
parameter.
color1, color2
(supported players: AS2)color1
is the primary border color, and color2
is the video control bar background color and secondary border color.
egm
(supported players: AS2)0
or 1
. Default is 0
. Setting to 1
enables the "Enhanced Genie Menu". This behavior causes the genie menu (if present) to appear when the user’s mouse enters the video display area, as opposed to only appearing when the menu button is pressed.
hd
(supported players: AS2)0
or 1
. Default is 0
. Setting to 1
enables HD playback by default. This has no effect on the Chromeless Player. This also has no effect if an HD version of the video is not available. If you enable this option, keep in mind that users with a slower connection may have an sub-optimal experience unless they turn off HD. You should ensure your player is large enough to display the video in its native resolution.
showsearch
(supported players: AS2)0
or 1
. Default is 1
. Setting to 0
disables the search box from displaying when the video is minimized. Note that if the rel
parameter is set to 0
then the search box will also be disabled, regardless of the value of showsearch
.