Screen.orientation is a read-only property that returns a ScreenOrientation object for the current screen orientation (MDN). Access it as window.screen.orientation, then read .type and .angle.
Read the notes below before you rely on this property. Prefer feature detection when support is limited.
Syntax
Use screen.orientation. Start with this line.
JavaScript
window.screen.orientation
Call
What it does
window.screen.orientation
Primary signature.
Built into the browser. Read screen.orientation on window.screen — no import required.
Library declarations
JavaScript
window.screen.orientation
Parameters
Parameter
Description
orientation
Required. Read-only ScreenOrientation
Return Value
Return Value
Description
*
ScreenOrientation object
JavaScript Examples
Example 1 — Read type and angle
Log the current orientation string and degrees.
JavaScript
if (screen.orientation) {
console.log(screen.orientation.type);
console.log(screen.orientation.angle);
} else {
console.log("screen.orientation not available");
}
Guard first. Confirm screen.orientation exists before reading fields.
Read type. A string such as "landscape-primary".
Read angle. Degrees for the current orientation.
Your values differ. Desktop monitors are often landscape; phones change as you rotate.
Example 2 — MDN Landscape / Portrait Switch
Branch on type — same idea as MDN’s example.
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 :(");
}
}
Listening for orientation change…
ScreenOrientation change: portrait-primary, 0 degrees.
How It Works
Attach to the object. The event lives on ScreenOrientation, not only on window.
Use event.target. Read the updated type and angle.
Rotate to test. On a phone/emulator, turn the device to fire change.
Desktop note. Many desktops rarely fire rotation events.
Compatibility
Browser Support
Screen.orientation is Baseline Widely available (MDN: since March 2023). Always read .type on the ScreenOrientation object.
✓ Baseline · Widely available
Screen.orientation
Returns a ScreenOrientation with type and angle — supported in modern evergreen browsers.
95%Widely available
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
orientationExcellent
Bottom line: Safe for modern web apps. Feature-detect screen.orientation for very old browsers, and prefer .type over treating orientation as a string.
Frequently Asked Questions
A read-only ScreenOrientation object for the current screen orientation. Access it as window.screen.orientation. Use orientation.type for strings like landscape-primary.
No. MDN marks Screen.orientation as Baseline Widely available (since March 2023). It is not Deprecated, Experimental, or Non-standard.
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. Locking uses ScreenOrientation.lock() / unlock() when allowed—not assignment to screen.orientation.
Listen for the change event on screen.orientation, then read type and angle again.