44

I'm using the following script to make my web app go fullscreen...

function enterFullscreen(){
    var element = document.getElementById('container');
    if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullScreen) {
        element.webkitRequestFullScreen();
    }
    l('Fullscreen Mode entered','internal');
}

And so, when I click the trigger button via $('button.toggle-fullscreen').click(function(){ enterFullscreen(); }); I do in fact enter fullscreen, only my element goes black. Just black, nothing else.

Anyone know how to fix this?

FYI I'm using Chrome 27.

7 Answers 7

39

The default background color of the browser's full-screen "visual environment" is black. Your content actually is there, but it's currently black text on black background, so you can't see it (try highlighting or pressing Ctrl+A to see for yourself).

If you want to make the background a different color, you must specify a CSS rule to set the background-color property to something other than the default. This was once done universally by setting a background-color property applied to the fullscreened element selected with the :fullscreen pseudo-class, but now the correct way to do so is to modify the element's associated ::backdrop peudo-element.

#container::backdrop {
    background-color: rgba(255,255,255,0);
}

Note that :fullscreen pseudo-class still works as a selector to alter other properties of fullscreened elements, but cannot reliably cause any background-related properties to be rendered. (If you wanted to be really robust, you could apply your background to both ::backdrop and :fullscreen.)

So, to apply a background color to any fullscreened element (i.e., not restricting our styling to any particular element(s) of interest), with support for browsers that either don't support ::backdrop or don't support :fullscreen background styles, you could do:

:fullscreen, ::backdrop {
    background-color: rgba(255,255,255,0);
}
7
  • My container is being used only as a structural element to hold everything (no visual styles), and requires a transparent background. Would I be able to set background-color: transparent? Apr 23, 2013 at 18:29
  • You can use the :fullscreen pseudo-class. I'll edit my answer.
    – apsillers
    Apr 23, 2013 at 19:38
  • still no luck! I tried to reproduce what's happening in jsFiddle but it won't let me take the app fullscreen unfortunately. Since the container div is essentially the entire page I tried switching the selector over to the <body> tag to see if it would make a difference, but I still can't seem to get it to not be black. I can't even seem to find where the black is being applied in the DOM inspector. Any other suggestions? Apr 25, 2013 at 0:45
  • @JodyHeavener Fiddle won't go fullscreen because iframe content isn't allowed to initiate fullscreen without special HTTP headers. However, you can see your fiddle as a stand-alone page by going to http://fiddle.jshell.net/[ID]/[versionNum]/show/ (e.g., fiddle.jshell.net/gtCSs/1/show) -- or just use your browser's right-click menu to "Open frame in new tab" or similar.
    – apsillers
    Apr 25, 2013 at 1:56
  • 1
    On my recent project, it took 1 additional step in webkit. I was applying fullscreen to the body element, and I needed to set the height and width to 100% so that it engulfed the screen and covered the default black: body:-webkit-full-screen { background-color: rgba(255,255,255,0); width:100%; height:100%; } Sep 29, 2014 at 22:19
27

None of the other answers is working for me (Chrome 70 or FF 63)

Adding this to the CSS file does work

::backdrop
{
    background-color: white;
}
0
24

I don't know the exact answer to your question, but this information might help:

I had a similar black background problem with enterFullscreen(document.body);. The background color became normal after I changed the line to enterFullscreen(document.documentElement);. The css I used is body{background-color: #D7D7D7; margin: 0px;}.

3
  • 1
    For info, I just made this tweak in reveal.js and it fixed an issue where presentation backgrounds were going black in full screen mode in Chrome only
    – Garry
    Sep 23, 2015 at 15:54
  • 1
    I don't no why Chrome is still doing this with document.body, but it worked for me too with document.documentElement. Chrome became not black if you pressed F11 (fullscreen by menu), but only with JavaScript document.body it will be black. Even if :fullscreen body is set transparent.
    – Robert
    Dec 17, 2015 at 15:06
  • I don't think this is just chrome specific. I just tested with firefox - 7 years later and they boys are still dealing with this problem.
    – Shmack
    Dec 17, 2022 at 5:30
11

Don't know why, but it seem that the background of the body element is not displayed in fullscreen or become transparent...

I fixed this by setting a background color to the html element, and it work just fine:

html {
    background-color: #ffffff;
    /* Or any color / image you want */
}
1
  • The accepted answer works, but so does this. Would love to know why (seems webkit specific) ...
    – Eclectic
    Jul 23, 2016 at 17:05
4

I spent hours to find a trick for this issue.

I ended by doing that :

  • Fixing a white color to backdrop
  • And using z-index, to push it down

Then :

  • Fixing a white color to the html page content
  • And using z-index, to push it up (above backdrop)

It works for me on Firefox and Chrome

::backdrop {
    z-index:0;  
    background-color: white !important;
}

html, *:fullscreen, *:-webkit-full-screen, *:-moz-full-screen {
    background-color: white !important;
    z-index:1;
}
1
  • Thanks, this still seems relevant today, I have a dialog element with a .dialog-content div which I make fullscreen with contentNode.requestFullScreen(), and all my content without a defined background-color went black. z-index does not seem to help but setting background-color: white means my black-on-white content is visible again.
    – Neek
    Jun 2 at 9:03
2

the main solution didn't work to me :-( I found another solution, but yes, in the css:

:-webkit-full-screen, :fullscreen, :-ms-fullscreen, :-moz-full-screen {
position: fixed;
width: 100%;
height: 100%;
top: 0; 
background: none;}

I understand this is for the position of my elements, but I no sure. Hope help to somebody. Bye and thanks.

1

The accepted answer works in most browsers, but in my tests not in IE11. For me this works in current Chrome, Firefox, Edge, IE 11 and Safari on iOS:

CSS:

body {
    background-color: #ffffff;
}

JS:

function openFullscreen () {
    let isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
    let elem = isSafari ? document.documentElement : document.body;
    let openFn = elem.requestFullscreen || elem.mozRequestFullScreen || elem.webkitRequestFullscreen || elem.msRequestFullscreen;
    if (openFn) {
        openFn.call(elem);
    }
};

edit: added exception for iOS/Safari which doesn't work with using body element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.