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.

Jody Heavener
  • 2,704
  • 5
  • 41
  • 70

7 Answers7

38

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);
}
apsillers
  • 112,806
  • 17
  • 235
  • 239
  • 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`? – Jody Heavener Apr 23 '13 at 18:29
  • You can use the [`:fullscreen`](https://developer.mozilla.org/en-US/docs/CSS/:fullscreen) pseudo-class. I'll edit my answer. – apsillers Apr 23 '13 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 `` 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? – Jody Heavener Apr 25 '13 at 00: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., http://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 '13 at 01:56
  • @JodyHeavener Your statement "*I can't even seem to find where the black is being applied*" seems to be founded on a misunderstanding. In fullscreen, the backgound is simply black by default. There is no style rule making it black; it's black because there is no existing style rule that says to make the currently-fullscreened element any other color. You shouldn't be looking for where the black is applied; you should be looking for where white (or whatever color you desire) *isn't* being applied. Applying a style to `body` won't help unless `body` is the exact element you're fullscreening. – apsillers Apr 25 '13 at 01:59
  • 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%; } – Justin Putney Sep 29 '14 at 22:19
  • this one doesn't work anymore on chrome – Hermanboxcar Jun 16 '22 at 02:45
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;
}
flappix
  • 2,038
  • 17
  • 28
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;}.

feilong
  • 649
  • 5
  • 7
  • 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 '15 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 '15 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 '22 at 05: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 */
}
Miaow
  • 864
  • 9
  • 23
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;
}
Rainbow
  • 41
  • 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 02 '23 at 09: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.

Drako
  • 769
  • 1
  • 8
  • 23
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.

klues
  • 847
  • 12
  • 21