Screen.orientation is a read-only instance property that returns a ScreenOrientation object for the current screen orientation. Learn type and angle, the MDN landscape/portrait switch, how to listen for rotation with change, and how this differs from older APIs—with five examples and try-it labs.
01
Kind
Read-only property
02
Returns
ScreenOrientation
03
Access
window.screen
04
Key fields
type, angle
05
Event
change
06
Status
Baseline widely
Fundamentals
Introduction
Phones and tablets rotate. Games and video UIs often want to know whether the screen is in portrait or landscape—and which way is “up.” The Screen Orientation API exposes that through window.screen.orientation.
The property itself is an object (ScreenOrientation), not a plain string. Beginners usually start with screen.orientation.type, which returns values like "landscape-primary" or "portrait-primary".
MDN notes that older, prefixed versions returned a string equivalent to ScreenOrientation.type. Modern code should treat screen.orientation as an object and read .type.
Concept
Understanding the Property
MDN: the orientation read-only property of the Screen interface returns the current orientation of the screen as a ScreenOrientation instance.
Instance — on window.screen.
Read-only property — you do not assign a new orientation object to it.
Object value — use .type, .angle, and events.
Baseline — Widely available (MDN: since March 2023).
An instance of ScreenOrientation representing the orientation of the screen.
Reference
🎨 Common type Values
type
Beginner meaning
portrait-primary
Usual upright portrait
portrait-secondary
Portrait, flipped the other way
landscape-primary
Usual landscape
landscape-secondary
Landscape, flipped (often “upside down”)
angle is a number of degrees of rotation (commonly 0, 90, 180, or 270, depending on the device).
Practice
🎯 MDN Landscape / Portrait Switch
MDN’s classic teaching example branches on screen.orientation.type:
JavaScript
switch (screen.orientation.type) {
case "landscape-primary":
console.log("That looks good.");
break;
case "landscape-secondary":
console.log("Mmm… the screen is upside down!");
break;
case "portrait-secondary":
case "portrait-primary":
console.log("Mmm… you should rotate your device to landscape");
break;
default:
console.log("The orientation API isn't supported in this browser :(");
}
Reactive
🔄 Listening for Orientation Changes
When the user rotates the device, ScreenOrientation fires a change event. Re-read type / angle inside the handler.
ScreenOrientation.lock() / unlock() can request a fixed orientation (for example fullscreen games), but browsers often require fullscreen or user activation and may reject the promise. Prefer reading orientation first; treat locking as an advanced, optional step.
Cheat Sheet
⚡ Quick Reference
Goal
Code
Get orientation object
screen.orientation
Read type string
screen.orientation.type
Read angle
screen.orientation.angle
On rotate
orientation.addEventListener("change", …)
MDN status
Baseline Widely available (Mar 2023)
Snapshot
🔍 At a Glance
Four facts about screen.orientation.
Kind
property
Read-only
Type
ScreenOrientation
Object
Via
window.screen
Screen object
Status
baseline
Widely available
Hands-On
Examples Gallery
Examples follow MDN Screen.orientation. Rotate a phone or resize a desktop window (when the browser reports a type) to see values change.
📚 Getting Started
Read the orientation object and practice the MDN switch.
Example 1 — Read orientation.type
Log the ScreenOrientation object and its type string.
JavaScript
if (screen.orientation) {
console.log(screen.orientation.type);
console.log(typeof screen.orientation.type);
} else {
console.log("screen.orientation not available");
}
Feature-detect screen.orientation, then read .type. Your string depends on how the device is held.
Example 2 — MDN Type Switch
Branch messages for landscape vs portrait (from MDN).
JavaScript
if (!screen.orientation) {
console.log("The orientation API isn't supported in this browser :(");
} else {
switch (screen.orientation.type) {
case "landscape-primary":
console.log("That looks good.");
break;
case "landscape-secondary":
console.log("Mmm… the screen is upside down!");
break;
case "portrait-secondary":
case "portrait-primary":
console.log("Mmm… you should rotate your device to landscape");
break;
default:
console.log("The orientation API isn't supported in this browser :(");
}
}
Screen.orientation is Baseline Widely available across modern browsers (MDN: since March 2023). Logos use the shared browser-image-sprite.png sprite from this project. Always read .type on the ScreenOrientation object.
✓ Baseline · Widely available
Screen.orientation
Read-only ScreenOrientation — current type and angle of the screen.
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerNo modern Screen.orientation object
Unavailable
orientationExcellent
Bottom line: Use screen.orientation.type for portrait/landscape strings, listen for change on rotate, and keep CSS media/orientation queries as the primary layout tool.
Wrap Up
Conclusion
window.screen.orientation returns a ScreenOrientation object for the current screen orientation. Read type and angle, use the MDN switch for landscape vs portrait messaging, and listen for change when the device rotates.
Read screen.orientation.type for portrait/landscape strings
Feature-detect screen.orientation before using it
Listen for change when UI should update on rotate
Keep responsive CSS as the main layout tool
Treat lock/unlock as optional and permission-sensitive
❌ Don’t
Assign to screen.orientation (the property is read-only)
Assume older prefixed APIs still return a bare string
Prefer legacy window.orientation for new apps
Rely only on JS orientation for critical CSS layout
Expect orientation lock to succeed without fullscreen / policy checks
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about orientation
ScreenOrientation for current screen rotation.
5
Core concepts
🖥️01
Read-only
on Screen
Kind
🔄02
Object
ScreenOrientation
Value
📱03
type
portrait / landscape
Field
📈04
change
on rotate
Event
🎯05
Baseline
widely available
Status
❓ Frequently Asked Questions
A read-only ScreenOrientation object describing the current screen orientation. Access it as window.screen.orientation. Use orientation.type for the string (for example landscape-primary).
No. MDN marks Screen.orientation as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
Common OrientationType strings: portrait-primary, portrait-secondary, landscape-primary, and landscape-secondary.
window.orientation is an older, non-standard number API. Prefer screen.orientation (ScreenOrientation) for modern code.
The Screen.orientation property itself is read-only. You read the ScreenOrientation object; locking/unlocking uses ScreenOrientation methods when allowed, not assignment to screen.orientation.
Listen for the change event on screen.orientation (ScreenOrientation), then read type/angle again.
Did you know?
CSS also has orientation media features (for example @media (orientation: landscape)). Use CSS for most layout changes, and screen.orientation when JavaScript needs the precise OrientationType string or angle.