Fullscreen toggling

Element.requestFullscreen()

Limited availability
  • Chrome71
  • Edge79
  • Firefox64
  • Safari16.4

Features it needs

screenfull's whole job is normalizing the vendor-prefixed versions of this API across engines. Now that every major browser ships the unprefixed requestFullscreen()/exitFullscreen() pair, that normalization layer is no longer needed for current versions.

When this applies

Toggling an element, such as a video player or image viewer, into and out of fullscreen.

The native approach

async function toggleFullscreen(el) {
  if (document.fullscreenElement) {
    await document.exitFullscreen();
  } else {
    await el.requestFullscreen();
  }
}

MDN reference

When the dependency is still right

An answer that always says "the platform covers it" is worse than no answer. These are the cases where this one does not hold.

  • You support Safari below 16.4, where the unprefixed API only recently landed.
  • You're targeting iOS Safari specifically. It still doesn't support fullscreen on arbitrary elements, only on the built-in video player.
  • You need the older vendor-prefixed fallback chain screenfull still maintains for browsers this old.

Packages this covers