JavaScript Document exitPointerLock() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

document.exitPointerLock() asynchronously releases a pointer lock previously requested with Element.requestPointerLock(). Call exit on the document; request on an element (MDN).

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call document.exitPointerLock. Start with this line.

JavaScript
document.exitPointerLock()
CallWhat it does
document.exitPointerLock()Primary signature.
document.exitPointerLock(...)Call with the arguments your case needs.

Built into the browser. Call exitPointerLock(...) on document — no import required.

Library declarations
JavaScript
document.exitPointerLock()

Parameters

This member has no parameters beyond those shown in the signature.

Return Value

Return ValueDescription
*Always undefined

JavaScript Examples

Example 1 — Feature Detect

Check both exit on document and request on an element before offering UI.

JavaScript
const el = document.createElement("div");
const canExit = typeof document.exitPointerLock === "function";
const canRequest = typeof el.requestPointerLock === "function";

console.log(canExit);    // true in supporting browsers
console.log(canRequest); // true in supporting browsers
console.log(canExit && canRequest); // ready for lock UI
Try It Yourself

How It Works

  1. Check exit. Limited availability means the method may be missing.
  2. Check request. Locking is on the element, not the document.
  3. Combine flags. Only show lock controls when both exist.
  4. Ship safely. Hide or degrade UI when detection fails.

Example 2 — Safe Exit When Locked

Guard with pointerLockElement, then call exitPointerLock().

JavaScript
function unlockPointer() {
  if (typeof document.exitPointerLock !== "function") {
    console.log("API missing");
    return;
  }
  if (!document.pointerLockElement) {
    console.log("already unlocked");
    return;
  }
  const result = document.exitPointerLock();
  console.log(result); // undefined
}

unlockPointer();
Try It Yourself

How It Works

  1. Detect first. Avoid calling a missing method.
  2. Check state. pointerLockElement is null when unlocked.
  3. Exit. Call exitPointerLock() only while locked.
  4. Ignore the return. It is always undefined — confirm via events.

Example 3 — Sync UI on pointerlockchange

Listen for lock changes so Esc unlocks update your UI too.

JavaScript
document.addEventListener("pointerlockchange", function () {
  const locked = Boolean(document.pointerLockElement);
  console.log(locked ? "locked" : "unlocked");
});

document.addEventListener("pointerlockerror", function () {
  console.log("pointerlockerror");
});

// After a user gesture on an element:
// el.requestPointerLock();
// Later: document.exitPointerLock();
Try It Yourself

How It Works

  1. Listen for change. Fires on lock and unlock (script or Esc).
  2. Read pointerLockElement. Non-null means locked.
  3. Listen for error. Failed requests fire pointerlockerror.
  4. Request needs a gesture. Call requestPointerLock from a click handler.

Browser Support

Document.exitPointerLock() is part of the Pointer Lock API. MDN marks it Limited availability (not Baseline). Feature-detect before production use.

✓ Limited availability

Document.exitPointerLock()

Widely implemented in desktop browsers for games and 3D views. Mobile and embedded contexts may lack or restrict it — always detect.

Limited Not Baseline
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
exitPointerLock() Feature-detect

Bottom line: Detect exitPointerLock + requestPointerLock, then unlock with events. See the MDN exitPointerLock() reference.

Frequently Asked Questions

It asynchronously releases a pointer lock previously requested through Element.requestPointerLock().
No. MDN does not mark Document.exitPointerLock() as Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline), so feature-detect in production.
undefined. It does not return a Promise. Track success or failure by listening for pointerlockchange and pointerlockerror.
exitPointerLock() is called on the document. requestPointerLock() is called on an element.
Check document.pointerLockElement. If it is non-null, that element is the lock target. It becomes null after a successful unlock.
Yes. Esc (and leaving the page) typically releases the lock. Listen for pointerlockchange so your UI stays in sync.

Next: getAnimations()

Learn document.getAnimations() to list CSS and WAAPI animations on the document.

getAnimations() tutorial →

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.

11 people found this page helpful