98

I have a form that is iframed into a web page. Upon completion of the form, a YouTube video is displayed from using iframe embed.

When I enter full screen mode of the YouTube video, nothing really happens.

Is the fullscreen of the nested iframe constrained by the dimensions of the parent iframe?

2

18 Answers 18

205
+25

In the current YouTube iframe (2021), you have to add fullscreen to the allow attribute:

<iframe allow="fullscreen;">

If I understand correctly you have an iframe that contains a second iframe (the youtube one).
Try adding the allowfullscreen attribute to the "parent" iframe.

For full browser support it should look like this:

<iframe src="your_page_url" 
        allowfullscreen="allowfullscreen"
        mozallowfullscreen="mozallowfullscreen" 
        msallowfullscreen="msallowfullscreen" 
        oallowfullscreen="oallowfullscreen" 
        webkitallowfullscreen="webkitallowfullscreen"> </iframe> 
3
  • 50
    you only need <iframe src="url" frameborder="0" allowfullscreen></iframe>, some other attributes are deprecated.
    – ViliusL
    Jan 5, 2015 at 17:45
  • 4
    in the new youtube code you have to add fullscreen to the content of the allow attribute. E.g. allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture; fullscreen"
    – Taras
    Apr 3, 2020 at 5:55
  • when I do <iframe src = '...?controls=0' allowfullscreen ></iframe>, then it does not work, and when the controls =1, then allowfullscreen works, how can I make it work when controls=0 Apr 30, 2020 at 6:36
62

React.JS People, remember allowFullScreen and frameBorder="0"

Without camel-case, react strips these tags out!

1
  • 8
    usage of allowFullScreen="allowFullScreen" and frameBorder="0" solved this. Apr 3, 2017 at 16:28
35

Adding allowfullscreen="allowfullscreen" and altering the type of YouTube embed fixed my issue.

4
  • 1
    Also needed to add allowfullscreen="allowfullscreen" on the parent iFrame
    – user147215
    Feb 2, 2015 at 18:56
  • 3
    This is not working for me. Is there any alternative @Neil?
    – SE_User
    Oct 14, 2016 at 11:06
  • I was facing this issue in ReactJs. It solved my problem.
    – habib
    Aug 9, 2019 at 7:17
  • In reactjs just putting allowFullScreen in iframe tag didn't solved my problem. But with allowFullScreen="allowFullScreen" in iframe prop solved my problem in reactjs. Nov 9, 2021 at 2:11
14

In HTML5, simply use:

<iframe src="https://www.youtube.com/embed/ID" allowfullscreen /> 

This attribute can be set to true if the frame is allowed to be placed into full-screen mode by calling it's Element.requestFullscreen() method. If this isn't set, the element can't be placed into full-screen mode. See Mozilla Docs

In React.js framework use property allowFullScreen.

Note that there are more answers pointing to different directions, so hope this post will unite and simplify all mentioned with latest valid approach.

1
  • Thanks for the "In React.js framework use property allowFullScreen."
    – o.z
    May 23, 2021 at 21:53
12

I had to add allowFullScreen attribute to the "parent" iframe. The case of the attribute does matter. I don't think Firefox or Edge/IE11 has a browser specific allowFullScreen attribute. So it looks something like this:

<iframe allowFullScreen='allowFullScreen' src='http://api.youtube.com/...'/>

0
9

Putting allowfullscreen inside iframe tag without setting it to true is already deprecated. The updated answer for this issue which is fullscreen is not available with embedded YouTube videos is to set allowfullscreen to true inside tag:

<iframe 
   id="player" 
   src="URL here" 
   allowfullscreen="true">
</iframe>

Tested and working for all browsers without issues.

0
6

The best solution and the easiest one to achieve this by using this simple code:

<iframe id="player" src="URL" allowfullscreen></iframe>

Tested and working for all browsers without issues.

Thank you

1
  • Putting allowfullscreen inside iframe is deprecated already. You need to set it to true to make it work.
    – Jeanne vie
    Feb 28, 2020 at 6:52
3

jut add allowfullscreen="true" to iframe

  <iframe src="URL here" allowfullscreen="true"> </iframe>
1
  • 1
    just adding allowfullscreen without any value also works
    – pref
    Feb 1, 2021 at 3:53
2

we can get the code below the video. In the share option, we will have an option embed. If we click on the embed we will get the code snippet for that video.

which will be similar to the below code

<iframe width="560" height="315" src="https://www.youtube.com/embed/GZh_Kj1rS74" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

The above code will help you to get the full-screen option.

1

I found a solution that worked for me on this page thanks to someone named @orangecoat-ciallella

https://www.drupal.org/node/1807158

The "full screen" button was not working in my Chrome browser on Ubuntu.

I was using the media_youtube module for D6. In the iframe it was using a video URL of the pattern //www.youtube.com/v/videoidhere.

I used the theme preprocessing function to make it output > //www.youtube.com/embed/videoidhere and it immediately started allowing the fullscreen button to work.

In short, try changing the /v/ to /embed/ in the YouTube URL if you're having a problem.

1

If adding allowfullscreen does not help, make sure you don't have &fs=0 in your iframe url.

1
  • We don't have to set the value of fs anymore because by default the value of fs is 1 which lets the expand button to show. I tried putting allowfullscreen inside the iframe but it doesn't work anymore. Updated fix is to set the value of allowfullscreen to true.
    – Jeanne vie
    Feb 28, 2020 at 6:57
1

You need to add these two attributes allow="fullscreen;" allowfullscreen to your iframe tag like this:

<iframe ...  allow="fullscreen;" allowfullscreen >
</iframe>

Note: for my case, adding just allowfullscreen was not enough to enable fullscreen mode on website.

1

In my personal blog the youtube videos are embedded with

 <div className="flex justify-center">
    <iframe width="600" height="350" src="https://www.youtube.com/embed/MoQa_zdmoKs?autoplay=1&mute=1" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture;fullscreen"></iframe>
</div>
0

easiest way to achieve this in 2021 is: Go to your desired youtube video, click share and pick embed. Copy and paste the code to your html and you are good to go!

0

Tested this below code on Edge & Chrome. Expands to full browser view, but not full-screen. I had to stick to this workaround as none of the above solutions worked for my case.

This also immediately auto-plays the video muted though.

<html>
<head>
<body>
<iframe src="https://www.youtube.com/embed/742lIJQVlSg?mute=1&autoplay=1"  frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto" allowfullscreen></iframe>
</body>
</head>
</html>
-1

Inserting after the outer-most iframe from inside the nested iframe fixed the issue for me.

var outerFrame = parent.parent.parent.$('.mostOuterFrame');
parent.$('<iframe />', {
    src: 'https://www.youtube.com/embed/BPlsqo2bk2M'
    }).attr({'allowfullscreen':'allowfullscreen',                             'frameborder':'0' 
    }).addClass('youtubeIframe')
        .css({
            'width':'675px',
            'height':'390px',
            'top':'100px',
            'left':'280px',
            'z-index':'100000',
            'position':'absolute'
         }).insertAfter(outerFrame);
-1

I managed to find a relatively clean straightforward way to do this. To see it working click on my webpage: http://developersfound.com/yde-portfolio.html and hover over the 'Youtube Demos' link.

Below are two snippets to show how this can be done quite easily:

I achieved this with an iFrame. Assuming this DOM is 'yde-home.html' Which is the source of your iFrame.

<!DOCTYPE html>
<html>
<head>
    <title>iFrame Container</title>
    <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
    <style type="text/css">.OBJ-1 { border:none; }</style>
    <script>
        $(document).ready(function() {
            $('#myHiddenButton').trigger('click');
        });
    </script>
</head>

<body>

    <section style="visibility: hidden;">
        <button id="myHiddenButton" onclick="$(location).attr('href', '"http://www.youtube.com/embed/wtwOZMXCe-c?version=3&amp;start=0&amp;rel=0&amp;fs=1&amp;wmode=transparent;");">View Full Screen</button>
    </section>

    <section class="main-area-inner" style="background:transparent;margin-left:auto;margin-right:auto;position:relative;width:1080px;height:720px;">
        <iframe src="http://www.youtube.com/embed/wtwOZMXCe-c?version=3&amp;start=0&amp;rel=0&amp;fs=1&amp;wmode=transparent;"
        class="OBJ-1" style="position:absolute;left:79px;top:145px;width:1080px;height:720px;">
        </iframe>
    </section>

</body>

</html>

Assume this is the DOM that loads the iFrame.

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>Full Screen Youtube</title>
    <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
    <script>
        $(document).ready(function() {});           
    </script>
</head>

<body>

    <iframe name="iframe-container" id="iframe-container" src="yde-home.html" style="width: 100%; height: 100%;">
        <p>Your browser does not support iFrames</p>
    </iframe>

</body>

</html>

I've also checked this against the W3c Validator and it validates a HTML5 with no errors.

It is also important to note that: Youtube embed URLs sometimes check to see if the request is coming from a server so it may be necessary to set up your test environment to listen on your external IP. So you may need to set up port forwarding on your router for this solution to work. Once you've set up port forwarding just test from the external IP instead of LocalHost. Remember that some routers need port forwarding from LocalHost/loopback but most use the same IP that you used to log into the router. For example if your router login page is 192.168.0.1, then the port forward would have to use 192.168.0.? where ? could be any unused number (you may need to experiment). From this address you would add the ports that your test environment listen from (normally 80, 81, 8080 or 8088).

-1

Noticed mine worked on chrome. Got it to work in Firefox by going to <about:config> and setting full-screen-api.allow-trusted-requests-only to false.

After full screen worked once, I could set that back to true, and full screen still worked which was quite perplexing.