JavaScript Document pointerLockElement Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

Document.pointerLockElement is a read-only property that returns the Element set as the target for mouse events while the pointer is locked. It is null if lock is pending, the pointer is unlocked, or the target is in another document (MDN).

Read the notes below before you get or set this property. Prefer feature detection when support is limited.

Syntax

Use document.pointerLockElement. Start with this line.

JavaScript
document.pointerLockElement
CallWhat it does
document.pointerLockElementPrimary signature.

Built into the browser. Read or assign document.pointerLockElement — no import required.

Library declarations
JavaScript
document.pointerLockElement

Parameters

ParameterDescription
GetterRequired. Locked Element or null
SetterOptional. Read-only — use request/exit APIs

Return Value

Return ValueDescription
*The current value of document.pointerLockElement.

JavaScript Examples

Example 1 — Read pointerLockElement

Usually null until the user locks the pointer.

JavaScript
const locked = document.pointerLockElement;
console.log(locked);                 // null when unlocked
console.log(locked === null);        // true
Try It Yourself

How It Works

  1. Read the getter. Returns an Element or null.
  2. Default page. Without an active lock, the value is null.
  3. Do not assign. The property is read-only.
  4. Use for status. Games check this to know if mouse look is active.

Example 2 — Watch pointerlockchange

MDN-style: request lock on click, then read the property when status changes.

JavaScript
const lockBtn = document.querySelector("#lock");
const box = document.querySelector("#box");

lockBtn.addEventListener("click", () => {
  box.requestPointerLock();
});

document.addEventListener("pointerlockchange", () => {
  const locked = document.pointerLockElement;
  lockBtn.disabled = Boolean(locked);
  console.log(locked ? locked.id : null);
});
Try It Yourself

How It Works

  1. User gesture. Click calls requestPointerLock() on the target element.
  2. Listen once. pointerlockchange fires on lock and unlock.
  3. Read status. Non-null means this document has an active lock target.
  4. UI sync. Disable Lock while locked; Esc or exit re-enables it.

Example 3 — Feature Detect

Safe check before using Pointer Lock APIs (Limited availability).

JavaScript
const canLock =
  "pointerLockElement" in document &&
  typeof Element.prototype.requestPointerLock === "function";

console.log(canLock);

if (canLock) {
  console.log(document.pointerLockElement);
} else {
  console.log("Pointer Lock not supported");
}
Try It Yourself

How It Works

  1. Check the property. "pointerLockElement" in document.
  2. Check the method. Ensure requestPointerLock exists on elements.
  3. Branch safely. Offer mouse-look only when both are available.
  4. Still may fail. Even with support, a lock request can be denied — listen for pointerlockerror.

Browser Support

Document.pointerLockElement has Limited availability on MDN (not Baseline). Feature-detect and provide a fallback when Pointer Lock is missing or denied.

✓ Limited availability

Document.pointerLockElement

Read-only Element with pointer lock — support varies across browsers.

Limited Feature-detect first
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Android WebView Supported · Modern WebView
Full support
pointerLockElement Limited

Bottom line: Safe to teach and use with detection. Pair with requestPointerLock, exitPointerLock, pointerlockchange, and pointerlockerror.

Frequently Asked Questions

The Element set as the target for mouse events while the pointer is locked in this document, or null if the lock is pending, the pointer is unlocked, or the target is in another document (MDN).
No. MDN marks Document.pointerLockElement as Limited availability (not Baseline). It is not Deprecated, Experimental, or Non-standard. Feature-detect before relying on it.
When pointer lock is not active, while a lock request is still pending, or when the locked element belongs to another document such as an iframe (MDN).
No. The property is read-only. To lock, call element.requestPointerLock(). To unlock, call document.exitPointerLock() or let the user press Esc.
Listen for the pointerlockchange event on document, then read document.pointerLockElement. Use pointerlockerror when a request fails.
fullscreenElement is the element in fullscreen mode. pointerLockElement is the element receiving locked mouse events. Games often use both together.

Next: prerendering

Learn whether the document is currently prerendering.

prerendering 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