JavaScript Screen unlockOrientation() Method

Beginner
⏱️ 11 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Deprecated
Non-standard
Instance method

What You’ll Learn

Screen.unlockOrientation() is a deprecated, non-standard instance method that cleared every orientation lock the page or app had set. Learn the no-argument call, the old vendor prefixes, when it could run (installed apps / fullscreen), and how to migrate to screen.orientation.unlock()—with five examples and try-it labs.

01

Kind

Instance method

02

Returns

Boolean

03

Status

Deprecated · Non-standard

04

Parameters

None

05

Modern path

orientation.unlock()

06

Context

App / fullscreen

Introduction

After a game locked the screen to landscape, it often needed a way to let the device rotate freely again. Older APIs did that with screen.unlockOrientation().

That approach is obsolete. Modern browsers unlock via the ScreenOrientation object from screen.orientation. This tutorial covers the legacy method so you can read old code and migrate it safely. Pair it with lockOrientation() when you meet both in the same codebase.

JavaScript
// Legacy only — do not use in new apps
// screen.unlockOrientation();
💡
Beginner tip

MDN: the old method only worked for installed Web apps or pages in fullscreen. A normal browser tab usually could not unlock orientation.

Understanding the Method

MDN: the unlockOrientation() method of the Screen interface removes all the previous screen locks set by the page/app.

  • Instance method — historically on window.screen.
  • Deprecated & Non-standard — not in any specification.
  • Parameters — none.
  • Returntrue unlocked / false could not unlock.

📝 Syntax

JavaScript
unlockOrientation()

Parameters

None.

Return value

A boolean: true if the orientation was successfully unlocked, false if it could not be unlocked.

🎯 Prefer ScreenOrientation.unlock()

LegacyModern
screen.unlockOrientation()screen.orientation.unlock()
Returns booleanReturns undefined (void)
Deprecated / non-standardScreen Orientation API
Pair with lockOrientationPair with orientation.lock()
JavaScript
// Modern idea
if (screen.orientation && typeof screen.orientation.unlock === "function") {
  screen.orientation.unlock();
  console.log("called orientation.unlock()");
}

🛡️ Legacy Feature-Detection Pattern

MDN’s examples normalize prefixed names (and sometimes fall through to modern unlock). Use this only when reading old code—not for new apps.

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

console.log(typeof unlockOrientationUniversal);
⚠️
Boolean vs void

Legacy unlock returns a boolean. Modern screen.orientation.unlock() returns undefined. Do not treat a modern call’s return value like true/false.

⚡ Quick Reference

GoalCode / note
Legacy unlockscreen.unlockOrientation()
Detect prefixesunlockOrientation || moz… || ms…
Modern replacementscreen.orientation.unlock()
Related lock (legacy)lockOrientation()
MDN statusDeprecated · Non-standard
New codeDo not use

🔍 At a Glance

Four facts about screen.unlockOrientation().

Kind
method

Instance

Returns
boolean

Unlocked?

Via
window.screen

When present

Status
deprecated

Non-standard

Examples Gallery

Examples follow MDN Screen.unlockOrientation(). Labs feature-detect and usually do not change your display—they report API availability.

📚 Getting Started

Detect the legacy API and study MDN’s call shapes without forcing an unlock.

Example 1 — Feature-Detect Prefixed Names

Find which unlock function (if any) exists on screen.

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

if (typeof unlockOrientationUniversal === "function") {
  console.log("legacy unlockOrientation API present");
} else {
  console.log("unlockOrientation not supported (expected on modern browsers)");
}
Try It Yourself

How It Works

Matches the usual vendor-prefix alias. Missing support is the normal modern outcome.

Example 2 — Safe Legacy Call

Show the no-argument call; only invoke if the API exists.

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

if (typeof unlockOrientationUniversal !== "function") {
  console.log("API missing; would have called unlockOrientation()");
} else {
  const ok = unlockOrientationUniversal();
  console.log(ok ? "Orientation was unlocked" : "Orientation unlock failed");
}
Try It Yourself

How It Works

On supporting engines, true/false means unlocked vs failed. Calling unlock when nothing is locked is usually harmless in legacy engines.

📈 MDN Pattern, Modern API & Snapshots

Compare MDN’s universal alias with today’s ScreenOrientation.unlock().

Example 3 — MDN Universal Alias (Study Shape)

MDN sometimes falls through to screen.orientation.unlock. We log which branch would run—without mixing boolean and void returns.

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

let branch = "none";
if (screen.unlockOrientation || screen.mozUnlockOrientation || screen.msUnlockOrientation) {
  branch = "legacy boolean unlock";
} else if (screen.orientation && screen.orientation.unlock) {
  branch = "modern orientation.unlock (void)";
}

console.log({
  typeofUnlock: typeof unlockOrientation,
  branch,
  tip: "Prefer calling screen.orientation.unlock() directly in new code."
});
Try It Yourself

How It Works

MDN’s if (unlockOrientation()) pattern assumes a boolean. That fits the legacy API, not modern unlock(), which returns undefined.

Example 4 — Modern orientation.unlock Check

Detect the replacement without requiring a prior lock.

JavaScript
const hasModern =
  !!(screen.orientation && typeof screen.orientation.unlock === "function");

console.log({
  hasModernUnlock: hasModern,
  currentType: screen.orientation ? screen.orientation.type : "(none)",
  tip: "Prefer screen.orientation.unlock() in new apps."
});
Try It Yourself

How It Works

Unlocking when nothing is locked is typically a no-op on the modern API—still feature-detect before calling.

Example 5 — Legacy vs Modern API Snapshot

One object summarizing what this browser exposes.

JavaScript
console.log({
  unlockOrientation: typeof screen.unlockOrientation,
  mozUnlockOrientation: typeof screen.mozUnlockOrientation,
  msUnlockOrientation: typeof screen.msUnlockOrientation,
  orientationUnlock: screen.orientation
    ? typeof screen.orientation.unlock
    : "no screen.orientation",
  status: "legacy unlockOrientation is deprecated & non-standard"
});
Try It Yourself

How It Works

Use this dump when auditing a codebase for leftover unlockOrientation / mozUnlockOrientation calls.

🚀 Common Use Cases

  • Reading / migrating old fullscreen games that called unlockOrientation.
  • Understanding vendor-prefixed orientation unlock history.
  • Pairing with legacy lockOrientation() during audits.
  • Teaching why orientation APIs are restricted to apps / fullscreen.
  • Planning a move to screen.orientation.unlock().

🔧 How It Works

1

App clears orientation locks

After a game or video exits landscape-only mode.

Intent
2

Legacy Screen.unlockOrientation

Boolean success/fail in installed apps or fullscreen.

Legacy
3

Modern ScreenOrientation.unlock

Void call on screen.orientation.

Today
4

Device can rotate freely again

UI should still look good in any orientation.

📝 Notes

Legacy / Deprecated Support

Screen.unlockOrientation() is Deprecated and Non-standard. Prefer screen.orientation.unlock(). Logos use the shared browser-image-sprite.png sprite from this project. Do not rely on the legacy method for production.

Deprecated · Non-standard

Screen.unlockOrientation()

Legacy orientation unlock — use ScreenOrientation.unlock() instead.

Legacy Avoid in new apps
Mozilla Firefox Legacy mozUnlockOrientation era — prefer orientation.unlock()
Avoid
Google Chrome Use ScreenOrientation.unlock() where available
Avoid legacy
Microsoft Edge Legacy msUnlockOrientation history — prefer modern API
Avoid legacy
Apple Safari Do not rely on screen.unlockOrientation()
Unavailable / Avoid
Opera Follow Chromium Screen Orientation API
Avoid legacy
Internet Explorer msUnlockOrientation legacy only
Legacy
unlockOrientation() Deprecated

Bottom line: Feature-detect only for migration. Prefer screen.orientation.unlock() in new code; never require orientation APIs for core UX.

Conclusion

screen.unlockOrientation() was a deprecated, non-standard way to clear orientation locks with a no-argument call. Feature-detect it only when migrating legacy code, and use screen.orientation.unlock() for new work.

Continue with Screen change, lockOrientation(), Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer screen.orientation.unlock() for new apps
  • Feature-detect before calling any unlock helper
  • Keep a UI that works in every orientation
  • Remove unlockOrientation / mozUnlockOrientation from codebases
  • Read lockOrientation() with this page

❌ Don’t

  • Use screen.unlockOrientation() in new production apps
  • Treat modern unlock() like a boolean return
  • Require orientation unlock APIs for core product flows
  • Ignore fullscreen / installed-app constraints from MDN
  • Skip checking MDN’s Deprecated and Non-standard warnings

Key Takeaways

Knowledge Unlocked

Five things to remember about unlockOrientation()

Deprecated non-standard orientation unlock method.

5
Core concepts
⚠️ 02

Deprecated

avoid in new code

Status
🚫 03

Non-standard

no public spec

Spec
🔄 04

Modern

orientation.unlock()

Replace
🎯 05

No args

clears all locks

API

❓ Frequently Asked Questions

It was a deprecated, non-standard method that removed all previous screen locks set by the page or app. Prefer ScreenOrientation.unlock() instead.
MDN marks Screen.unlockOrientation() as Deprecated and Non-standard. It is not Experimental. Do not use it in new code.
Use screen.orientation.unlock() from the Screen Orientation API. That is the modern path MDN recommends.
MDN: only for installed Web apps or for Web pages in fullscreen mode. Ordinary tabs usually could not unlock (or lock) orientation.
true if the orientation was successfully unlocked, false if it could not be unlocked.
Vendors shipped prefixed names (mozUnlockOrientation, msUnlockOrientation). Legacy snippets often feature-detect across those names.
Did you know?

Unlock is the twin of lock. If a legacy game called lockOrientation("landscape") on enter, it usually called unlockOrientation() on exit so the phone could rotate again—today that pair is orientation.lock() / orientation.unlock().

Next: Screen change Event

Learn the experimental Window Management Screen change event.

change →

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.

5 people found this page helpful