JavaScript Screen orientationchange Event

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

What You’ll Learn

Screen orientationchange is a deprecated, non-standard instance event that fired when the device orientation changed. Learn the old addEventListener / onorientationchange shapes, how it differs from Window orientationchange and from Screen change, and how to migrate to screen.orientation change—with five examples and try-it labs.

01

Kind

Instance event

02

Type

Event

03

Status

Deprecated · Non-standard

04

Handler

onorientationchange

05

Modern path

orientation.change

06

Fires when

Device rotates

Introduction

When a phone rotates from portrait to landscape, layouts often need a refresh. Older code sometimes listened for orientationchange on screen (or on window).

That Screen event is obsolete. Modern browsers expose orientation updates on screen.orientation via the Screen Orientation API. This tutorial covers the legacy Screen event so you can read old snippets and migrate them safely.

JavaScript
// Legacy only — do not use in new apps
// screen.addEventListener("orientationchange", () => { /* … */ });
💡
Beginner tip

For new work, always prefer screen.orientation.addEventListener("change", …) and then read type / angle.

Understanding the Event

MDN: the orientationchange event fires when the device’s orientation has changed.

  • Instance event — historically associated with Screen.
  • Deprecated & Non-standard — not in any specification.
  • Generic Event — no special orientation payload fields.
  • ReplacementScreenOrientation change.

📝 Syntax

Use the event name with addEventListener, or set the handler property:

JavaScript
addEventListener("orientationchange", (event) => { });

onorientationchange = (event) => { };

Event type

A generic Event.

🎯 Prefer ScreenOrientation change

LegacyModern
screen orientationchangescreen.orientation change
Deprecated / non-standardScreen Orientation API (Baseline)
Generic EventGeneric Event; read type / angle
onorientationchangeonchange on screen.orientation
JavaScript
screen.orientation.addEventListener("change", (event) => {
  const type = event.target.type;
  const angle = event.target.angle;
  console.log(`ScreenOrientation change: ${type}, ${angle} degrees.`);
});

⚖️ Related Events (Do Not Mix Them Up)

EventTargetStatus / note
orientationchangeScreenDeprecated · Non-standard (this page)
orientationchangeWindowDeprecated (separate MDN page)
changescreen.orientationModern rotate API — prefer this
changeScreen (Window Management)Experimental — see Screen change

⚡ Quick Reference

GoalCode / note
Legacy listenscreen.addEventListener("orientationchange", fn)
Legacy propertyscreen.onorientationchange = fn
Modern replacementscreen.orientation.addEventListener("change", fn)
Read new orientationscreen.orientation.type / .angle
MDN statusDeprecated · Non-standard
New codeDo not use

🔍 At a Glance

Four facts about Screen orientationchange.

Event type
Event

Generic

Status
deprecated

Non-standard

Via
screen

Legacy

Replace
orientation

.change

Examples Gallery

Examples follow MDN Screen: orientationchange event. Labs mostly feature-detect and show the modern replacement—legacy listeners often never fire on today’s browsers.

📚 Getting Started

Detect legacy hooks without relying on them for UX.

Example 1 — Feature-Detect Legacy Hooks

See whether onorientationchange exists on screen.

JavaScript
console.log({
  hasOnorientationchange: "onorientationchange" in screen,
  typeofHandler: typeof screen.onorientationchange,
  tip: "Screen orientationchange is deprecated & non-standard — prefer orientation.change"
});
Try It Yourself

How It Works

Missing support is expected on modern engines. Detect only when auditing legacy code.

Example 2 — Legacy addEventListener Shape (Safe)

Show MDN’s listen form; report if the browser ignores it.

JavaScript
try {
  screen.addEventListener("orientationchange", () => {
    console.log("legacy Screen orientationchange fired");
  });
  console.log("Attached orientationchange on screen (may never fire)");
} catch (err) {
  console.log("Could not attach:", err.name);
}
Try It Yourself

How It Works

Attaching may succeed even when the engine never dispatches the event—another reason not to depend on it.

📈 Property Handler, Modern API & Snapshot

Compare onorientationchange with today’s ScreenOrientation.change.

Example 3 — onorientationchange Property

MDN’s alternate handler property form.

JavaScript
if ("onorientationchange" in screen) {
  screen.onorientationchange = () => {
    console.log("legacy onorientationchange fired");
  };
  console.log("Assigned screen.onorientationchange");
} else {
  console.log("onorientationchange not available on screen (expected)");
}
Try It Yourself

How It Works

Assigning onorientationchange replaces any previous property handler. Prefer addEventListener on the modern API instead.

Example 4 — Modern screen.orientation change

MDN’s recommended replacement for device rotate.

JavaScript
if (screen.orientation && typeof screen.orientation.addEventListener === "function") {
  screen.orientation.addEventListener("change", (event) => {
    const type = event.target.type;
    const angle = event.target.angle;
    console.log(`ScreenOrientation change: ${type}, ${angle} degrees.`);
  });
  console.log("Listening on screen.orientation (preferred)");
} else {
  console.log("ScreenOrientation change not available");
}
Try It Yourself

How It Works

Rotate a phone or emulator to see the handler run. Desktop may rarely fire unless you change display orientation.

Example 5 — Legacy vs Modern API Snapshot

One object summarizing what this browser exposes.

JavaScript
console.log({
  screenOnorientationchange: "onorientationchange" in screen,
  windowOnorientationchange: "onorientationchange" in window,
  hasOrientation: !!screen.orientation,
  orientationChange: screen.orientation
    ? typeof screen.orientation.onchange
    : "no screen.orientation",
  currentType: screen.orientation ? screen.orientation.type : "(none)",
  status: "legacy Screen orientationchange is deprecated & non-standard"
});
Try It Yourself

How It Works

Use this dump when searching a codebase for leftover orientationchange / onorientationchange usage.

🚀 Common Use Cases

  • Reading / migrating old mobile pages that listened on screen.
  • Understanding why rotate handlers stopped firing after browser updates.
  • Teaching the move to screen.orientation change.
  • Auditing projects for deprecated Screen events to remove.
  • Contrasting with experimental Screen change (Window Management).

🔧 How It Works

1

User rotates the device

Portrait ↔ landscape (or another angle).

Trigger
2

Legacy Screen orientationchange

Old engines may dispatch; many modern ones do not.

Legacy
3

Modern ScreenOrientation.change

Listen on screen.orientation; read type and angle.

Today
4

UI adapts safely

Responsive CSS still helps when JS events are delayed.

📝 Notes

Legacy / Deprecated Support

Screen orientationchange is Deprecated and Non-standard. Prefer screen.orientation change. Logos use the shared browser-image-sprite.png sprite from this project. Do not rely on the legacy event for production.

Deprecated · Non-standard

Screen orientationchange

Legacy rotate event — use ScreenOrientation.change instead.

Legacy Avoid in new apps
Mozilla Firefox Prefer screen.orientation change
Avoid legacy
Google Chrome Use ScreenOrientation.change
Avoid legacy
Microsoft Edge Prefer modern Screen Orientation API
Avoid legacy
Apple Safari Do not rely on Screen orientationchange
Avoid
Opera Follow Chromium Screen Orientation API
Avoid legacy
Internet Explorer Legacy-era only — migrate away
Legacy
orientationchange Deprecated

Bottom line: Feature-detect only for migration. Prefer screen.orientation.addEventListener("change", …) and read type/angle. Keep responsive CSS as a baseline.

Conclusion

Screen orientationchange was a deprecated, non-standard way to notice device rotation. Feature-detect it only when migrating legacy code, and use screen.orientation change for new work.

Continue with orientation, Screen change, Window methods, or the JavaScript hub.

💡 Best Practices

✅ Do

  • Prefer screen.orientation.addEventListener("change", …)
  • Read type and angle after modern change
  • Keep responsive CSS so rotate still looks good without JS
  • Remove onorientationchange from codebases when migrating
  • Read orientation with this page

❌ Don’t

  • Use Screen orientationchange in new production apps
  • Assume attaching a listener means the event will fire
  • Confuse it with experimental Screen change
  • Skip checking MDN’s Deprecated and Non-standard warnings
  • Require orientation events for core product flows without a fallback

Key Takeaways

Knowledge Unlocked

Five things to remember about orientationchange

Deprecated non-standard Screen rotate event.

5
Core concepts
⚠️ 02

Deprecated

avoid in new code

Status
🚫 03

Non-standard

no public spec

Spec
🔄 04

Modern

orientation.change

Replace
🎯 05

Fallback

CSS + detect

UX

❓ Frequently Asked Questions

It is a deprecated, non-standard event that fired when the device orientation changed. Prefer the ScreenOrientation change event on screen.orientation instead.
MDN marks Screen: orientationchange as Deprecated and Non-standard. It is not Experimental. Do not use it in new code.
Listen for change on screen.orientation: screen.orientation.addEventListener("change", handler). That is the Screen Orientation API path MDN recommends.
Use addEventListener("orientationchange", handler) or the onorientationchange property on Screen (or historically on window for the Window version).
A generic Event. Re-read orientation details after it fires (or use the modern API’s type and angle).
They are related legacy ideas. Window: orientationchange is also deprecated. Screen: orientationchange is additionally Non-standard. Prefer ScreenOrientation.change for both migration paths.
Did you know?

MDN lists a separate deprecated orientationchange on Window as well. Even if "onorientationchange" in window is true, new apps should still migrate to screen.orientation change—not keep either legacy listener forever.

Next: JavaScript Window

Explore the Window object and browser APIs next.

Window →

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