Element: requestPointerLock() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The requestPointerLock() method of the Element interface lets you asynchronously ask for the pointer to be locked on the given element.

To track the success or failure of the request, it is necessary to listen for the pointerlockchange and pointerlockerror events at the Document level.

Note: In the current specification, requestPointerLock() only communicates the success or failure of the request by firing pointerlockchange or pointerlockerror events. A proposed update to the specification updates requestPointerLock() to return a Promise which communicates success or failure. This page documents the version that returns a Promise. However, note that this version is not yet a standard and is not implemented by all browsers. See Browser compatibility for more information.

Syntax

js
requestPointerLock()
requestPointerLock(options)

Parameters

options Optional

An options object that can contain the following properties:

unadjustedMovement Optional

Disables OS-level adjustment for mouse acceleration, and accesses raw mouse input instead. The default value is false; setting it to true will disable mouse acceleration.

Return value

A Promise that resolves with undefined.

Security

Transient activation is required when calling requestPointerLock(). The user has to interact with the page or a UI element in order for this feature to work. Also, the target element's associated document must be in the active state.

If calling requestPointerLock() immediately after releasing the pointer lock via the default unlock gesture (instead of through an exitPointerLock() call), the call will fail, even if a transient activation is available.

If calling requestPointerLock() with requestFullscreen(), the requestPointerLock() must be called first, because the requestFullscreen() will consume the state of transient activation.

The allow-pointer-lock sandbox token must be added when calling requestPointerLock() in an <iframe> element. Also, no other elements in other <iframe> elements may be in pointer lock mode.

Examples

Pointer lock is often used in online games, when you want your mouse movement to be focused on controlling the game, without the distraction of the mouse pointer moving around, going outside the game area, or reaching the edge of the window.

To enable pointer lock, you would get the user to interact with the UI in some way, perhaps by pressing a button, or the game canvas itself.

js
canvas.addEventListener("click", async () => {
  await canvas.requestPointerLock();
});

Operating systems enable mouse acceleration by default, which is useful when you sometimes want slow precise movement (think about you might use a graphics package), but also want to move great distances with a faster mouse movement (think about scrolling, and selecting several files). For some first-person perspective games however, raw mouse input data is preferred for controlling camera rotation — where the same distance movement, fast or slow, results in the same rotation. This results in a better gaming experience and higher accuracy, according to professional gamers.

To disable OS-level mouse acceleration and access raw mouse input, you can set the unadjustedMovement to true:

js
canvas.addEventListener("click", async () => {
  await canvas.requestPointerLock({
    unadjustedMovement: true,
  });
});

For more example code, see:

Specifications

Specification
Pointer Lock 2.0
# dom-element-requestpointerlock

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
requestPointerLock
Chrome – No support
Chrome 22 – 37 (Release date: 2012-09-25)
prefix
footnote Removed in 38 and later
prefix Implemented with the vendor prefix: webkit
Chrome – Full support
Chrome 37 (Release date: 2014-08-26)
footnote
footnote From version 92, returns a promise instead of undefined. The behavior reflects a specification change.
Edge – Full support
Edge 13 (Release date: 2015-11-12)
footnote
footnote From version 92, returns a promise instead of undefined. The behavior reflects a specification change.
Firefox – No support
Firefox 14 – 49 (Release date: 2012-07-17)
prefix
prefix Implemented with the vendor prefix: moz
Firefox – Full support
Firefox 50 (Release date: 2016-11-15)
footnote Full support
Opera – No support
Opera 15 – 24 (Release date: 2013-07-02)
prefix
footnote Removed in 25 and later
prefix Implemented with the vendor prefix: webkit
Opera – Full support
Opera 24 (Release date: 2014-09-02)
footnote
footnote From version 78, returns a promise instead of undefined. The behavior reflects a specification change.
Safari – Full support
Safari 10.1 (Release date: 2017-03-27)
footnote
footnote From version 18.4, returns a promise instead of undefined. The behavior reflects a specification change.
Chrome Android – No support
Chrome Android
footnote
footnote See bug 40290045
Firefox for Android – No support
Firefox for Android 14 – 49 (Release date: 2012-06-26)
prefix
prefix Implemented with the vendor prefix: moz
Firefox for Android – Full support
Firefox for Android 50 (Release date: 2016-11-15)
footnote Full support
Opera Android – No support
Opera Android
footnote
footnote See bug 40290045
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet 1.5 – 2.1 (Release date: 2013-09-25)
prefix
prefix Implemented with the vendor prefix: webkit
Samsung Internet – Full support
Samsung Internet 3 (Release date: 2015-04-10)
footnote
footnote From version 16, returns a promise instead of undefined. The behavior reflects a specification change.
WebView Android – No support
WebView Android
footnote
footnote See bug 40290045
WebView on iOS – No support
WebView on iOS
footnote No support
options.unadjustedMovement parameter
Chrome – Full support
Chrome 88 (Release date: 2021-01-19)
footnote
footnote Supported on macOS Catalina 10.15.1+, Windows, and ChromeOS. Not yet supported on Linux.
Edge – Full support
Edge 88 (Release date: 2021-01-21)
footnote
footnote Supported on macOS Catalina 10.15.1+, Windows, and ChromeOS. Not yet supported on Linux.
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 74 (Release date: 2021-02-02)
footnote
footnote Supported on macOS Catalina 10.15.1+, Windows, and ChromeOS. Not yet supported on Linux.
Safari – Full support
Safari 18.4 (Release date: 2025-03-31)
footnote Full support
Chrome Android – No support
Chrome Android
footnote
footnote See bug 40290045
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – No support
Opera Android
footnote
footnote See bug 40290045
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – No support
Samsung Internet
footnote
footnote See bug 40290045
WebView Android – No support
WebView Android
footnote
footnote See bug 40290045
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.
Requires a vendor prefix or different name for use.
Has more compatibility info.

See also