orientation
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
The orientation
manifest member is used to specify the default orientation for your web application.
It defines how the app should be displayed when launched and during use, in relation to the device's screen orientation, particularly on devices that support multiple orientations.
Note: The app's orientation can be changed during runtime through various means, such as using the Screen Orientation API.
Syntax
/* Keyword values */
"orientation": "any"
"orientation": "natural"
"orientation": "portrait"
"orientation": "portrait-primary"
"orientation": "portrait-secondary"
"orientation": "landscape"
"orientation": "landscape-primary"
"orientation": "landscape-secondary"
Values
orientation
-
A string that specifies the default orientation for the web app. If the
orientation
member is not specified or an invalid value is provided, the web app will typically use the device's natural orientation and any user or system-level orientation settings.The
orientation
value must be one of the following keywords:any
-
Displays the web app in any orientation allowed by the device's operating system or user settings. It allows the app to rotate freely to match the orientation of the device when it is rotated.
natural
-
Displays the web app in the orientation considered most natural for the device, as determined by the browser, operating system, user settings, or the screen itself. It corresponds to how the device is most commonly held or used:
- On devices typically held vertically, such as mobile phones,
natural
is usuallyportrait-primary
. - On devices typically used horizontally, such as computer monitors and tablets,
natural
is usuallylandscape-primary
.
When the device is rotated, the app may or may not rotate so as to match the device's natural orientation; this behavior may vary depending on the specific device, browser implementation, and user settings.
- On devices typically held vertically, such as mobile phones,
portrait
-
Displays the web app with height greater than width. It allows the app to switch between
portrait-primary
andportrait-secondary
orientations when the device is rotated. portrait-primary
-
Displays the web app in portrait mode, typically with the device held upright. This is usually the default app orientation on devices that are naturally portrait. Depending on the device and browser implementation, the app will typically maintain this orientation even when the device is rotated.
portrait-secondary
-
Displays the web app in inverted portrait mode, which is
portrait-primary
rotated 180 degrees. Depending on the device and browser implementation, the app will typically maintain this orientation even when the device is rotated. landscape
-
Displays the web app with width greater than height. It allows the app to switch between
landscape-primary
andlandscape-secondary
orientations when the device is rotated. landscape-primary
-
Displays the web app in landscape mode, typically with the device held in its standard horizontal position. This is usually the default app orientation on devices that are naturally landscape. Depending on the device and browser implementation, the app will typically maintain this orientation even when the device is rotated.
landscape-secondary
-
Displays the web app in inverted landscape mode, which is
landscape-primary
rotated 180 degrees. Depending on the device and browser implementation, the app will typically maintain this orientation even when the device is rotated.
Description
To understand the orientation
manifest member, it's important to be familiar with the following orientation-related concepts:
- Device orientation: Defines how the device is physically held or positioned.
- Screen orientation: Defines the physical orientation of the device's display.
- App orientation: Defines how the app's content is displayed relative to the screen orientation.
When a device is rotated, it typically changes the screen orientation. For example, rotating a mobile phone from vertical to horizontal usually switches the screen from portrait to landscape mode. Without any specific orientation set in the manifest, most apps will adjust their layout to fit this new screen orientation.
The manifest's orientation
member allows you to control how your app responds to these changes. By specifying a preferred orientation for your app, you can decide whether your app should adapt to screen orientation changes or maintain a fixed layout regardless of how the device is held. For example, by setting "orientation": "portrait-primary"
, you can indicate that you prefer your app to always be displayed in upright portrait mode relative to the screen, even if the device is rotated. The browser or operating system will attempt to honor this preference when possible.
The example below illustrates how a web app's layout might appear when a mobile phone is rotated. For this example, assume that the app's orientation
value is set to any
, allowing the app to rotate between all orientation
values when the mobile phone is rotated. Also assume that both the phone and the browser support all orientations. The sequence shows a clockwise rotation of the phone, with each position rotated from the starting position as follows:
- Top-left:
portrait-primary
(starting position) - Top-right:
landscape-primary
(90 degrees) - Bottom-left:
portrait-secondary
(180 degrees) - Bottom-right:
landscape-secondary
(270 degrees)
Scope and default behavior
The specified orientation
is applied to all top-level browsing contexts of the web app.
If a browser supports the specified orientation
value, it will use this as the default app orientation throughout the app's lifespan, unless overridden at runtime.
This means that browsers will revert to this default orientation whenever the top-level browsing context is navigated.
Choosing a preferred orientation for your web app
By setting a specific orientation, you can ensure that your web app is displayed optimally for its content and user interface. For example, a video app is often better suited to landscape orientation, while a reading app typically works better in portrait orientation.
Not specifying an orientation can also be a deliberate choice, allowing your web app to adapt flexibly to different devices and user preferences.
Manifest orientation
vs. Screen Orientation API behavior
While the orientation
manifest member sets the default orientation of the web app, the orientation of a top-level browsing context can be changed once the web app is running using the Screen Orientation API.
The orientation
values are similar across the web app manifest and the Screen Orientation API, but their behavior and purposes differ.
-
Web app manifest:
- Suggests the preferred default orientation of the web app using the
orientation
manifest member. - Sets the initial orientation when the app is launched.
- Suggests the preferred default orientation of the web app using the
-
Screen Orientation API:
-
Uses orientation values to lock the screen to a specific orientation.
-
Allows dynamic changes to orientation during runtime (for example, locking orientation using
screen.orientation.lock()
).
Note: The Screen Orientation API's
lock()
method has limited support across browsers. Check its compatibility if you plan to use it to dynamically change screen orientation during runtime. -
Platform and browser limitations
When adding the orientation preference for your app, keep the following considerations and limitations mind:
- Browser vendors and device manufacturers decide which orientations and
display
modes are compatible. - Certain UI/UX concerns and platform conventions may limit which screen orientations and display modes can be used together.
- Support for specific
orientation
values may vary depending on the device and platform. - Some devices may not support all
orientation
values, such asportrait-secondary
andlandscape-secondary
. - Some browsers might not allow changing the default orientation of a web app while in while in certain display modes (e.g.,
"display": "browser"
).
Examples
Specifying a fixed orientation for a web app
This example sets the app's orientation to portrait-primary
. Assuming browser and device support, the app will always display in upright portrait mode even when the device is rotated.
{
"name": "My Web App",
"orientation": "portrait-primary"
}
Setting a flexible orientation for a web app
Consider a photo viewing and editing app. In the app's manifest file, as shown below, orientation
is set to any
. This allows the app to be launched in the device's current orientation and adapt to both portrait
and landscape
orientations as users rotate their devices. This orientation
setting will enable users to view and edit photos comfortably in whichever orientation best suits the current display or their current usage context.
{
"name": "PhotoGallery Pro",
"short_name": "PhotoGal",
"description": "A professional photo gallery and editing application",
"start_url": "/index.html",
"display": "standalone",
"orientation": "any",
"icons": [
{
"src": "icon-192.png",
"sizes": "192x192",
"type": "image/png"
}
],
"related_applications": [
{
"platform": "play",
"url": "https://play.google.com/store/apps/details?id=com.example.photogallery"
}
]
}
Specifications
Specification |
---|
Web Application Manifest # orientation-member |
Browser compatibility
BCD tables only load in the browser