JavaScript Element requestFullscreen() Method

Beginner
⏱️ 12 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Limited availability
Instance method

What You’ll Learn

Element.requestFullscreen() is an instance method from the Fullscreen API. It asks the browser to display an element in fullscreen mode. Learn the Promise-based flow, user-gesture rules, optional navigationUI settings, and five try-it labs.

01

Kind

Instance method

02

Action

Enter fullscreen

03

Returns

Promise

04

Gesture

User activation

05

Exit

exitFullscreen()

06

Status

Limited availability

Introduction

Video players, games, slideshows, and image galleries often need a fullscreen view. requestFullscreen() is the standard way to expand a specific element to fill the screen while keeping your page logic in JavaScript.

The call is asynchronous: it returns a Promise that resolves when fullscreen mode is active, or rejects if the browser denies the request. You typically call it from a click handler because MDN requires transient user activation.

💡
Beginner tip

Use document.fullscreenElement to see which element is fullscreen right now. Call document.exitFullscreen() to leave fullscreen mode.

This page is part of JavaScript Element. Related: document.fullscreenElement, document.exitFullscreen(), and the JavaScript hub.

Understanding the requestFullscreen() Method

Calling el.requestFullscreen() (or el.requestFullscreen(options)) asks the browser to make that element fullscreen. The element must be connected to a document and allowed by the page’s Permissions Policy.

  • It is an instance method on Element (Fullscreen API).
  • Returns a Promise that resolves with undefined on success (MDN).
  • Requires user activation — start from a click or key handler.
  • Works on standard HTML elements and <svg> (MDN).
  • Not allowed on <dialog> elements (MDN).
  • Listen for fullscreenchange to react when mode toggles.

📝 Syntax

General forms of Element.requestFullscreen (MDN):

JavaScript
requestFullscreen()
requestFullscreen(options)

Parameters

  • options (optional) — controls transition behavior (MDN):
    • navigationUI"auto" (default), "hide", or "show"
    • keyboardLock"none" (default) or "browser"
    • screen — a ScreenDetailed object for multi-monitor setups

Return value

A Promise resolved with undefined when fullscreen is active (MDN).

Exceptions

  • The promise may reject with TypeError if the element is not allowed, not in a document, or fullscreen is blocked by policy (MDN).

Common patterns

JavaScript
const box = document.getElementById("box");

// Basic — call from a click handler
box.requestFullscreen().catch(console.error);

// Toggle with document.fullscreenElement
if (document.fullscreenElement) {
  document.exitFullscreen();
} else {
  box.requestFullscreen();
}

// Show browser navigation UI
document.documentElement.requestFullscreen({ navigationUI: "show" });

⚡ Quick Reference

GoalCode
Enter fullscreenel.requestFullscreen()
With optionsel.requestFullscreen({ navigationUI: "show" })
Check active elementdocument.fullscreenElement
Exit fullscreendocument.exitFullscreen()
Return valuePromise<undefined>
MDN statusLimited availability (not Baseline)

🔍 At a Glance

Four facts to remember about Element.requestFullscreen().

Returns
Promise

Resolves undefined

Status
limited

Not Baseline

Gesture
required

User activation

Check
fullscreenElement

Current target

📋 requestFullscreen() vs vendor prefixes vs exitFullscreen()

requestFullscreen()Vendor prefixesexitFullscreen()
Called onElement to expandSame (legacy)document
PurposeEnter fullscreenEnter fullscreenLeave fullscreen
ReturnsPromiseVaries by browserPromise
Standard todayYes (Fullscreen API)Legacy fallback onlyYes
Best forNew codeVery old browsersToggle off / cleanup

Examples Gallery

Examples follow MDN Element.requestFullscreen() patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

Click-to-fullscreen and Promise handling from a user gesture.

Example 1 — Button Click Fullscreen

Call requestFullscreen() on a div from a button click.

JavaScript
const box = document.getElementById("box");
const btn = document.getElementById("go");

btn.addEventListener("click", () => {
  box.requestFullscreen().catch((err) => {
    console.error("Fullscreen failed:", err.message);
  });
});
Try It Yourself

How It Works

The browser only allows fullscreen after user activation. Always attach requestFullscreen() to a click or key handler and handle promise rejection.

Example 2 — Toggle With fullscreenElement

Enter or exit fullscreen depending on the current state (MDN pattern).

JavaScript
const box = document.getElementById("box");

function toggleFullscreen() {
  if (document.fullscreenElement) {
    document.exitFullscreen();
    return;
  }
  box.requestFullscreen().catch(console.error);
}
Try It Yourself

How It Works

document.fullscreenElement is null when nothing is fullscreen. Use it to build a single toggle button or keyboard shortcut.

📈 Practical Patterns

Video players, navigation UI, and event listeners.

Example 3 — Video Fullscreen (MDN)

Put a <video> element into fullscreen on Enter or Shift+F.

JavaScript
const video = document.querySelector("video");

document.addEventListener("keydown", (event) => {
  if (event.key === "Enter" || event.key === "F") {
    if (document.fullscreenElement) {
      document.exitFullscreen();
      return;
    }
    video.requestFullscreen().catch((err) => {
      console.error(`Error: ${err.message}`);
    });
  }
});
Try It Yourself

How It Works

MDN uses keyboard shortcuts for demo purposes. The page needs focus, and the key event provides the required user activation.

Example 4 — navigationUI Option

Request fullscreen on the root element and show browser navigation UI (MDN).

JavaScript
const root = document.documentElement;

root
  .requestFullscreen({ navigationUI: "show" })
  .then(() => {
    console.log("Fullscreen with navigation UI");
  })
  .catch((err) => {
    console.error(err.name, err.message);
  });
Try It Yourself

How It Works

navigationUI: "hide" maximizes screen space. "show" keeps page navigation controls visible (MDN).

Example 5 — fullscreenchange Listener

Update UI when the user enters or leaves fullscreen manually.

JavaScript
const status = document.getElementById("status");

document.addEventListener("fullscreenchange", () => {
  if (document.fullscreenElement) {
    status.textContent = "Fullscreen: " + document.fullscreenElement.id;
  } else {
    status.textContent = "Exited fullscreen";
  }
});
Try It Yourself

How It Works

Users can press Esc or switch apps. A fullscreenchange listener keeps your UI in sync even when you did not call exitFullscreen() yourself.

🚀 Common Use Cases

  • Expanding a video player to fill the screen.
  • Immersive image galleries and slideshow presentations.
  • Game canvases and interactive demos that need maximum space.
  • Presentation mode for charts, dashboards, or document viewers.
  • Custom fullscreen buttons alongside native video controls.
  • Teaching the Fullscreen API with toggle and event-listener patterns.

🧠 How requestFullscreen() Works

1

User activates the page

A click or key press provides transient user activation (MDN).

Gesture
2

Call requestFullscreen on target

You call el.requestFullscreen() on the element to expand.

Request
3

Browser checks policy

Permissions Policy, element type, and iframe rules are validated.

Permission
4

Promise resolves; fullscreenchange fires

document.fullscreenElement points at the active element.

📝 Notes

  • Not Deprecated, Experimental, or Non-standard on MDN. Limited availability (not Baseline).
  • Returns a Promise, not a synchronous boolean.
  • Requires transient user activation (MDN).
  • Controlled by Permissions Policy fullscreen (MDN).
  • Iframes need allowfullscreen (or allow="fullscreen").
  • Listen for fullscreenchange and fullscreenerror on document.
  • Related: document.fullscreenElement, document.exitFullscreen(), :fullscreen, JavaScript hub.

Limited Availability Support

Element.requestFullscreen() is part of the Fullscreen API and is not Baseline on MDN. Desktop browsers generally support it well; mobile Safari has important limitations. Always feature-detect, call from a user gesture, and handle promise rejection.

Limited availability · Not Baseline

Element.requestFullscreen()

Async request to display an element in fullscreen mode.

Limited Not Baseline
Google Chrome Supported · Desktop & Android
Yes
Microsoft Edge Supported · Chromium
Yes
Mozilla Firefox Supported · Desktop
Yes
Apple Safari Partial · iOS limits non-video elements
Limited
Opera Supported · Chromium-based
Yes
Internet Explorer Legacy vendor-prefixed APIs only
No
requestFullscreen() Limited

Bottom line: Call from a click handler, catch promise errors, listen for fullscreenchange, and test on your target browsers — especially iOS Safari for video vs generic elements.

Conclusion

Element.requestFullscreen() is the standard way to expand an element to fill the screen. It returns a Promise, needs a user gesture, and pairs with document.fullscreenElement and document.exitFullscreen().

Continue with requestPointerLock(), :fullscreen, shadowRoot, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Call requestFullscreen() from a click or key handler
  • Use .catch() on the returned Promise
  • Listen for fullscreenchange to sync UI state
  • Check document.fullscreenElement before toggling
  • Provide a visible exit control for accessibility

❌ Don’t

  • Call fullscreen on page load without user activation
  • Assume mobile Safari behaves like desktop Chrome
  • Forget iframe allowfullscreen permissions
  • Ignore promise rejection when permission is denied
  • Trap users with no way to exit fullscreen

Key Takeaways

Knowledge Unlocked

Five things to remember about Element.requestFullscreen()

Async fullscreen requests from a user gesture—Promise in, events out.

5
Core concepts
📄 02

Gesture

required

Security
✍️ 03

Check

fullscreenElement

State
04

Status

limited

MDN
05

Exit

exitFullscreen

Pair

❓ Frequently Asked Questions

It issues an asynchronous request to display the element in fullscreen mode (MDN). The method returns a Promise that resolves when the transition completes.
No. MDN does not mark it Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline) because support varies, especially on mobile.
A Promise that resolves with undefined when fullscreen mode is active, or rejects with an exception if permission is denied or the element is not eligible (MDN).
Yes. MDN: transient user activation is required — call it from a user gesture such as a button click or key press handler.
Standard HTML elements or SVG (MDN). The element must be in a document, not a dialog, and allowed by Permissions Policy. Iframes need the allowfullscreen attribute.
Call document.exitFullscreen() or listen for fullscreenchange and check document.fullscreenElement. Users can also press Esc in most browsers.
Did you know?

The Fullscreen API is separate from CSS :fullscreen styling and PWA display-mode: fullscreen. requestFullscreen() is a runtime JavaScript request on a specific element, usually triggered by a user click.

Next: requestPointerLock()

Learn how to lock the mouse pointer for games and 3D apps.

requestPointerLock() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful