The definitive source of the best
JavaScript libraries, frameworks, and plugins.

  • ×


    Simple wrapper for cross-browser usage of the JavaScript Fullscreen API
    Filed under  › 

    • 🔾69%Overall
    • 5,762
    • 24.8 days
    • 🕩615
    • 👥19


    Simple wrapper for cross-browser usage of the JavaScript Fullscreen API, which lets you bring the page or any element into fullscreen. Smoothens out the browser implementation differences, so you don't have to.

    This package is feature complete. No new features will be accepted.



    Only 0.7 kB gzipped.

    Download the production version or the development version.

    $ npm install screenfull

    Also available on cdnjs.



    if (screenfull.isEnabled) {

    Vanilla JavaScript

    document.fullscreenEnabled =
        document.fullscreenEnabled ||
        document.mozFullScreenEnabled ||
    function requestFullscreen(element) {
        if (element.requestFullscreen) {
        } else if (element.mozRequestFullScreen) {
        } else if (element.webkitRequestFullScreen) {
    if (document.fullscreenEnabled) {
    // This is not even entirely comprehensive. There's more.


    Supported browsers

    Note: In order to use this package in Internet Explorer, you need a Promise polyfill.

    Note: Safari is supported on desktop and iPad, but not on iPhone. This is a limitation in the browser, not in Screenfull.



    Fullscreen the page

    document.getElementById('button').addEventListener('click', () => {
        if (screenfull.isEnabled) {
        } else {
            // Ignore or do something else

    Fullscreen an element

    const element = document.getElementById('target');
    document.getElementById('button').addEventListener('click', () => {
        if (screenfull.isEnabled) {

    Fullscreen an element with jQuery

    const element = $('#target')[0]; // Get DOM element from jQuery collection
    $('#button').on('click', () => {
        if (screenfull.isEnabled) {

    Toggle fullscreen on a image with jQuery

    $('img').on('click', event => {
        if (screenfull.isEnabled) {

    Detect fullscreen change

    if (screenfull.isEnabled) {
        screenfull.on('change', () => {
            console.log('Am I fullscreen?', screenfull.isFullscreen ? 'Yes' : 'No');

    Remove listeners with:'change', callback);

    Detect fullscreen error

    if (screenfull.isEnabled) {
        screenfull.on('error', event => {
            console.error('Failed to enable fullscreen', event);

    See the demo for more examples, and view the source.

    Fullscreen an element with Angular.js

    You can use the Angular.js binding to do something like:

    <div ngsf-fullscreen>
        <p>This is a fullscreen element</p>
        <button ngsf-toggle-fullscreen>Toggle fullscreen</button>

    Fullscreen the page with Angular 2

    import {Directive, HostListener} from '@angular/core';
    import screenfull = require('screenfull');
        selector: '[toggleFullscreen]'
    export class ToggleFullscreenDirective {
        @HostListener('click') onClick() {
            if (screenfull.isEnabled) {
    <button toggleFullscreen>Toggle fullscreen<button>



    Make an element fullscreen.

    Accepts a DOM element. Default is <html>. If called with another element than the currently active, it will switch to that if it's a decendant.

    If your page is inside an <iframe> you will need to add a allowfullscreen attribute (+ webkitallowfullscreen and mozallowfullscreen).

    Keep in mind that the browser will only enter fullscreen when initiated by user events like click, touch, key.

    Returns a promise that resolves after the element enters fullscreen.


    Brings you out of fullscreen.

    Returns a promise that resolves after the element exits fullscreen.


    Requests fullscreen if not active, otherwise exits.

    Returns a promise that resolves after the element enters/exits fullscreen.

    .on(event, function)

    Events: 'change' | 'error'

    Add a listener for when the browser switches in and out of fullscreen or when there is an error.

    .off(event, function)

    Remove a previously registered event listener.


    Alias for .on('change', function)


    Alias for .on('error', function)


    Returns a boolean whether fullscreen is active.


    Returns the element currently in fullscreen, otherwise null.


    Returns a boolean whether you are allowed to enter fullscreen. If your page is inside an <iframe> you will need to add a allowfullscreen attribute (+ webkitallowfullscreen and mozallowfullscreen).


    Exposes the raw properties (prefixed if needed) used internally: requestFullscreen, exitFullscreen, fullscreenElement, fullscreenEnabled, fullscreenchange, fullscreenerror


    How can I navigate to a new page when fullscreen?

    That's not supported by browsers for security reasons. There is, however, a dirty workaround. Create a seamless iframe that fills the screen and navigate to the page in that instead.

    $('#new-page-btn').click(() => {
        const iframe = document.createElement('iframe')
        iframe.setAttribute('id', 'external-iframe');
        iframe.setAttribute('src', '');
        iframe.setAttribute('frameborder', 'no'); = 'absolute'; = '0'; = '0'; = '0'; = '0'; = '100%'; = '100%';
        $(document.body).prepend(iframe); = 'hidden';


    Show All