JavaScript Screen unlockOrientation() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

screen.unlockOrientation() was a legacy helper that removed orientation locks set by the page/app. It returns true on success or false on failure (MDN). Prefer screen.orientation.unlock().

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

Syntax

Call screen.unlockOrientation. Start with this line.

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

Built into the browser. Call unlockOrientation(...) on a Screen — no import required.

Library declarations
JavaScript
screen.unlockOrientation()

Parameters

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

Return Value

Return ValueDescription
*true or false

JavaScript Examples

Example 1 — Feature-Detect

See which unlock path exists in this browser.

JavaScript
const modern = !!(screen.orientation && screen.orientation.unlock);
const legacy = !!(
  screen.unlockOrientation ||
  screen.mozUnlockOrientation ||
  screen.msUnlockOrientation
);

console.log(modern ? "modern unlock()" : "no modern unlock");
console.log(legacy ? "legacy unlockOrientation" : "no legacy API");
Try It Yourself

How It Works

  1. Check screen.orientation.unlock. Modern Screen Orientation API.
  2. Check legacy names. Includes vendor prefixes from old browsers (MDN).
  3. Log both. Helps decide which path (if any) to call.
  4. Prefer modern. Do not build new features on unlockOrientation.

Example 2 — Modern unlock()

MDN replacement: screen.orientation.unlock().

JavaScript
if (screen.orientation && screen.orientation.unlock) {
  try {
    screen.orientation.unlock();
    console.log("unlocked");
  } catch (err) {
    console.log(err.name); // SecurityError, …
  }
} else {
  console.log("not supported");
}
Try It Yourself

How It Works

  1. Guard on orientation.unlock. Skip when missing.
  2. Call unlock(). Clears orientation locks for the document (MDN).
  3. Catch errors. Hidden tabs / policy can throw SecurityError.
  4. No boolean return. Unlike the legacy API, modern unlock returns undefined.

Example 3 — Legacy unlockOrientation

MDN-style feature-detect across prefixed names (literacy only).

JavaScript
const unlockOrientation =
  screen.unlockOrientation ||
  screen.mozUnlockOrientation ||
  screen.msUnlockOrientation;

if (typeof unlockOrientation === "function") {
  const ok = unlockOrientation.call(screen);
  console.log(ok ? "unlocked" : "failed");
} else {
  console.log("legacy API missing");
}
Try It Yourself

How It Works

  1. Pick the first available name. Covers unprefixed and vendor prefixes.
  2. Call with screen as this. Important when storing the function reference.
  3. Read the boolean. true means unlocked; false means it could not unlock (MDN).
  4. Do not ship this. Prefer screen.orientation.unlock() in new apps.

Browser Support

Screen.unlockOrientation() is Deprecated and Non-standard on MDN. It is not part of any specification. Prefer screen.orientation.unlock().

✓ Deprecated · Non-standard

Screen.unlockOrientation()

Legacy orientation unlock. Feature-detect only for literacy; ship ScreenOrientation.unlock() for new work.

Legacy Deprecated API
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
screen.unlockOrientation() Avoid

Bottom line: Literacy only. Use screen.orientation.unlock() and treat orientation lock as optional / permission-sensitive.

Frequently Asked Questions

MDN: Screen.unlockOrientation() removes all previous screen locks set by the page/app. Prefer ScreenOrientation.unlock() instead.
Yes. MDN marks Screen.unlockOrientation() as Deprecated and Non-standard. It is not part of any specification and is no longer on track to become a standard.
Use screen.orientation.unlock() from the Screen Orientation API (MDN). That is the modern path.
MDN: only for installed Web apps or for Web pages in fullscreen mode. Ordinary tabs usually could not unlock orientation.
true if the orientation was successfully unlocked, false if it could not be unlocked (MDN).
Vendors shipped prefixed names (mozUnlockOrientation, msUnlockOrientation). Legacy snippets often feature-detect across those names (MDN).

Next: Screen change event

Learn how to listen when screen properties change.

change event 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