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()
Call
What 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 Value
Description
*
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
already unlocked
(or undefined if a lock was active)
How It Works
Detect first. Avoid calling a missing method.
Check state.pointerLockElement is null when unlocked.
Exit. Call exitPointerLock() only while locked.
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();
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.