JavaScript Screen lockOrientation() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

screen.lockOrientation(orientation) was a legacy way to lock the screen into one or more orientation strings (MDN). Today it is Deprecated and Non-standard — literacy only. Prefer screen.orientation.lock().

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

Syntax

Call screen.lockOrientation. Start with this line.

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

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

Library declarations
JavaScript
screen.lockOrientation(orientation)

Parameters

ParameterDescription
orientationRequired. String or array of orientation names

Return Value

Return ValueDescription
*boolean — authorized vs denied

JavaScript Examples

Example 1 — Detect Legacy Lock Helpers

Feature-detect unprefixed and vendor-prefixed names (MDN pattern).

JavaScript
const lockOrientationUniversal =
  screen.lockOrientation ||
  screen.mozLockOrientation ||
  screen.msLockOrientation;

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

How It Works

  1. Pick the first function among unprefixed / moz / ms names.
  2. Missing on Chromium / Safari is normal — the API never became Baseline.
  3. Presence ≠ usable — fullscreen / app context still mattered (MDN).
  4. Literacy goal — recognize old code; do not build on it.

Example 2 — Lock with a String (MDN)

Ask for landscape-primary using the universal helper.

JavaScript
const lockOrientationUniversal =
  screen.lockOrientation ||
  screen.mozLockOrientation ||
  screen.msLockOrientation;

if (typeof lockOrientationUniversal !== "function") {
  console.log("unsupported");
} else if (lockOrientationUniversal("landscape-primary")) {
  console.log("Orientation was locked");
} else {
  console.log("Orientation lock failed");
}
Try It Yourself

How It Works

  1. One string locks to that orientation requirement (MDN).
  2. true means authorized — not that rotation finished instantly.
  3. false means denied (wrong context, policy, or engine).
  4. Array form allows several orientations (e.g. both landscapes).

Example 3 — Prefer screen.orientation.lock()

MDN replacement: Promise-based lock (often needs fullscreen on mobile).

JavaScript
document.querySelector("button").addEventListener("click", async () => {
  if (!screen.orientation || typeof screen.orientation.lock !== "function") {
    console.log("ScreenOrientation.lock not supported");
    return;
  }
  try {
    await screen.orientation.lock("landscape");
    console.log("Locked to landscape");
  } catch (err) {
    console.log(err.name + ": " + err.message);
  }
});
Try It Yourself

How It Works

  1. Detect screen.orientation.lock — the standard replacement (MDN).
  2. Await the Promise — resolves on success; rejects with DOMExceptions.
  3. Fullscreen often required on mobile browsers before lock succeeds.
  4. Unlock with screen.orientation.unlock() when done.

Browser Support

screen.lockOrientation() is Deprecated and Non-standard. Sparse legacy support (notably Firefox and older Edge / IE). Absent on Chrome and Safari. Prefer screen.orientation.lock() and treat locking as optional.

✓ Deprecated · Non-standard

Screen.lockOrientation()

Legacy orientation lock — boolean return; use ScreenOrientation.lock() instead.

Legacy Not for new code
Google Chrome No lockOrientation()
No
Microsoft Edge Legacy Edge / IE era only; Chromium Edge: no
No
Apple Safari No lockOrientation()
No
Opera No lockOrientation()
No
Mozilla Firefox Legacy support (prefixed historically)
Limited
Internet Explorer IE11 / msLockOrientation era
Limited
lockOrientation() Legacy

Bottom line: Recognize prefixes for literacy; ship screen.orientation.lock(). See the MDN lockOrientation() reference.

Frequently Asked Questions

It was a non-standard method that locked the screen into a specified orientation (a string or an array of strings). MDN: prefer ScreenOrientation.lock() instead.
MDN marks Screen.lockOrientation() as Deprecated and Non-standard. It is not Experimental. Do not use it in new code.
Use screen.orientation.lock(orientation) from the Screen Orientation API. It returns a Promise and is the path MDN recommends.
MDN: only for installed Web apps or for Web pages in fullscreen mode. Ordinary tabs usually could not lock orientation.
true if locking was authorized, false if denied. MDN notes this does not guarantee the screen is already locked — there may be a delay.
Vendors shipped prefixed names (mozLockOrientation, msLockOrientation). Legacy snippets often feature-detect across those names (MDN).

Next: unlockOrientation()

Continue with the matching deprecated unlock method.

unlockOrientation() →

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.

18 people found this page helpful