Website publishing

Fullscreen on iPhone for Embedded Games: The Expanded-View Fallback

iPhone Safari has no Fullscreen API for page elements. Check the allow attribute, build a CSS expanded view with a close button and test on a real device.

PlayKovo Team3 min read
Games currently available on PlayKovo. Open a title to see its current listing.

You embed a game, test it on your laptop, tap the fullscreen button and everything works. Then a visitor on an iPhone reports that the button does nothing. It is not a bug in the game or your page. On iPhone, Safari does not offer the Fullscreen API for ordinary page elements, so there is nothing for the button to call. For a games section where a large share of visitors are on phones, that is worth solving properly. This post explains the limitation, what you can build instead, and how to check that your embed is set up for the cases where fullscreen does work.

What works where

  • Desktop browsers and Android Chrome: fullscreen works on an element, if the iframe has allow="fullscreen" and the request comes from a tap or click.
  • iPad: supports the Fullscreen API on elements in current Safari versions.
  • iPhone: no fullscreen for page elements. It is available for video.

Treat the iPhone limitation as permanent for planning purposes, and feature-detect rather than checking the device name. A button that fails silently is worse than no button.

Check the embed code first

If fullscreen fails on desktop or Android too, check the iframe. The game's own fullscreen button, if it has one, needs the permission from the embedding page. Our post on the allow attribute explains the values, and what every part of the iframe code does shows the standard embed. If you use the embed code PlayKovo provides, do not strip attributes. Many CMS editors do, as covered in pasting the embed into a CMS.

Build your own expanded view

For iPhone, offer a button that makes the game's container fill the visible screen. You are not hiding the browser's toolbars, but you remove your header, menu, sidebar and ads from view, and give the game the whole viewport.

<button id="expand" type="button">Expand</button>
<div id="frame" class="game-frame">
  <iframe src="https://playkovo.com/embed/GAME-SLUG" allow="fullscreen" ...></iframe>
</div>

<style>
.game-frame.expanded { position: fixed; inset: 0; z-index: 9999; background: #000; }
.game-frame.expanded iframe { width: 100%; height: 100%; }
body.lock { overflow: hidden; }
</style>

<script>
const frame = document.getElementById('frame');
document.getElementById('expand').addEventListener('click', () => {
  const on = frame.classList.toggle('expanded');
  document.body.classList.toggle('lock', on);
  if (on) addCloseButton(); else removeCloseButton();
});
</script>

Details that matter:

  1. Always include a visible close button inside the expanded view, in a corner, with a large tap target. A player who cannot find the way out will leave your site.
  2. Use 100dvh, not 100vh, if you set a height in CSS. On iPhone, 100vh includes the area under the address bar, so part of the game is hidden. inset: 0 on a fixed element avoids the problem.
  3. Lock page scroll while expanded, so a swipe does not scroll the page behind the game.
  4. Respect safe areas with env(safe-area-inset-*) padding for your close button, so it does not sit under a notch.
  5. Do not put your own ad or sticky bar over the expanded view. The game may show its own promotions, and you are not allowed to block them. See ads inside embedded games.

Feature-detect, then choose

const canFullscreen = !!(frame.requestFullscreen || frame.webkitRequestFullscreen);

button.addEventListener('click', async () => {
  if (canFullscreen) {
    try { await (frame.requestFullscreen || frame.webkitRequestFullscreen).call(frame); return; }
    catch {}
  }
  toggleExpanded();   // the CSS fallback
});

Label the button neutrally, such as "Expand", so it is true on every device. On iPhone you can add a small hint: "Add this page to your home screen for a full-screen experience". Do not promise features you have not tested.

Portrait games on phones

Many phone games are portrait, and the standard 16:9 embed box wastes space for them. Combine the expanded view with the portrait layout from portrait games in an embed. The feed's screenOrientation value tells you which games need it.

Test on a real iPhone

Simulators do not reproduce Safari's toolbar behavior reliably. Test with a real device, in both orientations, with the address bar visible and hidden, and check that:

  • The expand button appears and opens the expanded view.
  • The close button is reachable and works.
  • Page scroll is locked, and returns afterward.
  • The game receives taps in all areas of the screen.
  • Rotating the device keeps the view correct.

If something looks wrong, go through embed troubleshooting: five problems and their fixes. Game developers who want to handle fullscreen inside the game can read fullscreen and resize for HTML5 games.

We use optional cookies for site analytics and site advertising. You can change your choice later. Privacy policy.