Element.requestPointerLock() is an instance method from the Pointer Lock API. It locks the mouse pointer on an element—ideal for FPS games and 3D viewers. Learn Promise handling, unadjustedMovement, pointerlockchange events, and five try-it labs.
01
Kind
Instance method
02
Action
Lock pointer
03
Returns
Promise
04
Gesture
User activation
05
Exit
exitPointerLock()
06
Status
Limited availability
Fundamentals
Introduction
First-person games and 3D demos often need the mouse to control a camera without the cursor leaving the game area or hitting the screen edge. requestPointerLock() hides the pointer and reports movement through movementX and movementY on pointermove events.
The call is asynchronous: it returns a Promise. MDN also recommends listening for pointerlockchange and pointerlockerror on document to track success or failure across browsers. You must call it from a user gesture.
💡
Beginner tip
Use document.pointerLockElement to see which element currently has the lock. Press Esc or call document.exitPointerLock() to unlock.
Element.requestPointerLock() is part of the Pointer Lock API and is not Baseline on MDN. Desktop browsers support it well for games; mobile support is limited. Always feature-detect, call from a user gesture, and handle promise rejection plus pointerlockerror.
✓ Limited availability · Not Baseline
Element.requestPointerLock()
Async request to lock the mouse pointer on an element.
LimitedNot Baseline
Google ChromeSupported · Desktop
Yes
Microsoft EdgeSupported · Chromium
Yes
Mozilla FirefoxSupported · Desktop
Yes
Apple SafariLimited · check target platform
Limited
OperaSupported · Chromium-based
Yes
Internet ExplorerLegacy mozPointerLockElement APIs
No
requestPointerLock()Limited
Bottom line: Call from a click handler, use movementX/Y while locked, listen for pointerlockchange, and test on desktop targets — mobile pointer lock is often unavailable.
Wrap Up
Conclusion
Element.requestPointerLock() is the standard way to hide the cursor and read relative mouse movement for games and 3D viewers. It returns a Promise, needs a user gesture, and pairs with document.pointerLockElement and document.exitPointerLock().
Offer unadjustedMovement: true for FPS games when supported
Provide Esc instructions or an unlock button
❌ Don’t
Request lock on page load without user activation
Assume mobile browsers support pointer lock
Confuse pointer lock with setPointerCapture()
Ignore pointerlockerror when the request fails
Trap users with no way to exit lock mode
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Element.requestPointerLock()
Lock the pointer from a click—read relative motion with movementX/Y.
5
Core concepts
📝01
Returns
Promise
API
📄02
Gesture
required
Security
✍️03
Motion
movementX/Y
Input
✅04
Status
limited
MDN
⚡05
Exit
exitPointerLock
Pair
❓ Frequently Asked Questions
It asynchronously asks the browser to lock the pointer on the given element (MDN). The mouse cursor is hidden and movement is delivered via movementX and movementY on pointer events.
No. MDN does not mark it Deprecated, Experimental, or Non-standard. It is Limited availability (not Baseline) because support varies across browsers and platforms.
A Promise that resolves with undefined when the lock succeeds (MDN). Also listen for pointerlockchange and pointerlockerror on document for broader compatibility.
Yes. MDN: transient user activation is required — call it from a click or other user gesture on an active document.
An optional option that disables OS mouse acceleration and uses raw input (MDN). Set { unadjustedMovement: true } for FPS-style camera control.
Press Esc (default unlock gesture) or call document.exitPointerLock(). Listen for pointerlockchange and check document.pointerLockElement.
Did you know?
Pointer lock is different from setPointerCapture(), which routes events to an element but keeps the cursor visible. Pointer lock hides the cursor and is built for unlimited relative movement in games and 3D apps.