Cordova doesn't ship with a single global "landscape off" switch that works identically on every platform. Instead, you disable landscape orientation through platform-specific configuration—primarily screen-orientation settings in Android's manifest and iOS's project plist—plus, where needed, a runtime plugin call. The correct combination depends on whether you want the entire app locked to portrait from launch, or only specific screens. On Android, the change lives in the activity's android:screenOrientation attribute; on iOS, it lives in the list of supported interface orientations. Getting both consistent is the key condition for a reliable portrait lock.
This guide walks through each platform, covers the runtime-plugin alternative, and explains the failure points—like orientation remaining unlocked at launch, or a plugin call silently doing nothing—so you can verify the lock actually holds.
Why orientation locking isn't one setting in Cordova
Cordova is a bridge: it wraps a native WebView inside a native application container. Orientation is a property of that native container, not of the HTML, CSS, or JavaScript running inside it. Browsers expose orientation APIs, but locking orientation is a native window decision that the operating system enforces before your web code runs.
That's why you'll find no orientation key in config.xml alone that magically changes behavior on both platforms. There are two legitimate places to enforce a portrait lock:
1: Native configuration — the Android manifest and the iOS project files. This locks orientation from the moment the native window is created, including the splash screen and any native dialogs. 2: Runtime plugin — a plugin such as cordova-plugin-screen-orientation lets JavaScript call screen.lockOrientation, which dynamically restricts orientation after the app and WebView are already running.
Native configuration is the right default for "this whole app is portrait." Runtime locking is right for mixed apps—for example, a portrait-first app that must allow landscape only on a video or chart screen. Most bugs people hit come from mixing the two without understanding which one wins where.
Prerequisites before you start
Before editing anything, confirm your setup so the steps below map onto your project:
A working Cordova project. Run cordova platform list to see which platforms (android, ios, browser, electron, etc.) are installed. The platform folders (platforms/android, platforms/ios) must exist. If not, add them with cordova platform add android or cordova platform add ios. Know your Android activity name. In a default Cordova project it's derived from the widget ID, typically something like MainActivity. For iOS, you'll edit the Xcode project's Info.plist (or the project settings in Xcode). This is easier on a machine with Xcode installed.
A crucial warning: files inside platforms/ are generated. Cordova can regenerate or overwrite them when you run cordova platform remove/add, or during a clean build. If you edit platforms/android/.../AndroidManifest.xml directly and later re-add the platform, your edits vanish. The durable approach is to edit the source templates (or pin the change via a config hook), which we cover in a dedicated section.
Disabling landscape on Android
Android determines orientation per activity through the android:screenOrientation attribute on the element. Setting it to portrait tells the system to keep that activity in portrait and ignore rotation.
Step 1: Locate the manifest
Find the manifest at:
platforms/android/app/src/main/AndroidManifest.xml
(On older Cordova versions the path may be platforms/android/AndroidManifest.xml or platforms/android/app/AndroidManifest.xml. Search for AndroidManifest.xml under platforms/android if you're unsure.)
Step 2: Set screenOrientation on the main activity
Inside the block, locate the that has the android:name ending in MainActivity (often with a android:label="@string/launch_name" and an containing MAIN/LAUNCHER). Add or change the attribute:
Expected result: the activity element looks roughly like:
The android:configChanges list often already includes orientation, which is fine—it tells Android your app handles rotation itself rather than recreating the activity. With screenOrientation="portrait", rotation won't occur in the first place, so the two settings coexist cleanly.
Step 3: Rebuild and install
Run:
Success check: rotate the device physically or via the emulator's rotation control. The UI should stay upright. If it flips, the manifest edit didn't take effect—see the failure notes below.
Choosing the right orientation value
portrait allows both upright and upside-down portrait depending on the device and Android version behavior; portrait does not mean "upright only." If you specifically want upright-only, use sensorPortrait (which allows the portrait orientations the sensors report) or, for a hard lock that ignores sensors entirely, portrait generally keeps the device in the standard portrait orientation on most devices. For most apps, portrait is the correct, least surprising choice. Avoid locked, which is not a valid value; valid values include portrait, landscape, sensorPortrait, sensorLandscape, userPortrait, fullSensor, and unspecified, among others.
One nuance: android:screenOrientation on an activity affects that activity. If your app uses additional native activities (a custom splash activity, a plugin-provided share or camera activity), each is governed by its own manifest entry, though most plugin activities already declare an orientation or use unspecified. Locking the main activity covers the WebView where your app actually lives.
Disabling landscape on iOS
iOS controls orientation through the set of "Supported interface orientations" declared in the app's Info.plist (and, for some configurations, through the app delegate's supportedInterfaceOrientationsForWindow: method). Removing landscape entries means the system won't rotate the window into landscape at all.
Step 1: Open the plist or Xcode target settings
In the Cordova project, the file is typically:
platforms/ios//-Info.plist
You can edit it directly, but the safer route on a Mac is to open the generated Xcode project and, under the target's General tab, find Deployment Info → Device Orientation and uncheck Landscape Left and Landscape Right, leaving only Portrait (and optionally Upside Down).
Step 2: Edit the orientation keys in the plist
The relevant keys are UISupportedInterfaceOrientations and, for iPad, UISupportedInterfaceOrientations~ipad. Set them to portrait only:
If an iPad-specific array exists, give it the same treatment (portrait only, plus UIInterfaceOrientationPortraitUpsideDown only if you actually want upside-down). If the plist uses a different variable structure through Xcode's build settings, keep the array minimal and consistent.
Step 3: Rebuild and verify
Install on a device or simulator, then rotate. Expected result: the app stays in portrait at all times. On iPad, note that iPads run iPhone apps in a compatibility mode unless you've configured iPad support, and iPad multitasking (Split View) imposes its own orientation behavior; a portrait-only declaration constrains the app's own window but iPad system conventions can still surprise you. If the app is iPhone-only, this is not a concern.
The app-delegate caveat
Some Cordova iOS projects (older ones, or those where you customized the template) include a CDVAppDelegate or a custom app delegate with a method that returns supported orientations. If landscape reappears despite a portrait-only plist, search the iOS project for supportedInterfaceOrientationsForWindow and check whether it returns a mask that includes landscape. iOS combines the plist declaration with the delegate method, and the effective set is effectively the intersection in the standard case—but a delegate override can reintroduce landscape if it's written to do so. For stock Cordova, the plist is authoritative and you won't need to touch the delegate.
The runtime approach with a screen-orientation plugin
If you need conditional locking—portrait generally but landscape for one screen—native configuration alone can't do it, because it applies to the whole native activity. That's where cordova-plugin-screen-orientation comes in. It wraps the platform APIs and exposes screen.lockOrientation and screen.unlockOrientation to JavaScript.
Step 1: Install the plugin
This plugin depends on the W3C Screen Orientation API being present in the WebView; on modern Android WebViews and iOS WKWebView it is.
Step 2: Keep native defaults permissive if you want runtime control
Here's the subtle part: if you lock portrait natively and try to unlock to landscape at runtime, the native lock wins and the runtime unlock won't produce landscape. So decide which layer owns orientation.
Whole-app portrait forever: native lock only. Don't add runtime orientation calls. Portrait with an occasional landscape screen: leave native orientation permissive (or set unspecified on Android and include landscape in the plist on iOS), then lock portrait at startup in JavaScript and unlock only where needed.
Step 3: Lock and unlock in JavaScript
After deviceready, call:
and to release:
On supported platforms, portrait maps to the primary portrait orientation. If you need upside-down portrait as well, some implementations accept arrays like ['portrait-primary', 'portrait-secondary']; behavior varies by platform and plugin version, so check the plugin's README for your version rather than assuming. The plugin forwards to Android's setRequestedOrientation and iOS's orientation mask accordingly.
Step 4: Check success
Log the return or attach a failure handler where the API supports promises/callbacks in your plugin version, and physically rotate. A common symptom is that screen.lockOrientation throws or no-ops if called before deviceready—so wrap the call in a deviceready listener:
If you call it at module load time before the plugin is ready, you'll see no effect and possibly a console error.
Persisting your changes so they survive platform regeneration
Direct edits under platforms/ are fragile. When Cordova re-adds a platform—something that happens in CI pipelines, after cordova platform rm/add, or when switching Cordova versions—your manifest and plist edits revert to the defaults.
There are two robust patterns:
Edit the source template. Cordova keeps platform templates in the cordova-* platform packages it downloads, usually under node_modules or a global Cordova cache, not in your project. Modifying those is brittle across updates. A cleaner Cordova-native approach is to use a build hook.
Use a config hook. Add a hook script to config.xml that runs after_prepare and rewrites the platform files to your desired state. For Android, the hook can open platforms/android/app/src/main/AndroidManifest.xml, find the activity element, and set android:screenOrientation="portrait" if absent. For iOS, it can patch the generated plist. This is deterministic and rebuild-safe.
A minimal hook registration in config.xml looks like:
and the script uses Node's fs to read, modify, and write the file. The exact manipulation (regex versus a proper XML library) matters: regex is quick but can break on unusual formatting; an XML parser is safer for production. Either way, test the hook by running cordova prepare and then verifying the generated files.
Alternatively, some teams keep a single orientation-setting plugin or a small custom plugin that applies the manifest attribute at build time, but a build hook is the lightest solution that doesn't add runtime code.
Platform regeneration is the most common reason a "portrait lock" mysteriously stops working after a fresh checkout in CI. If you're on a team, document the hook in the project README so nobody "fixes" the manifest by hand.
Common failures and how to diagnose them
Landscape still appears at launch
Symptom: the app opens in portrait but can rotate, or the splash appears in landscape before snapping to portrait.
Likely cause: native orientation wasn't actually set (edit lost, wrong activity element, or hook didn't run). Check by inspecting the built manifest inside the APK (aapt dump xmltree on Android, or open the generated plist in the built .app bundle) rather than trusting the source file. Reversible first check: run cordova prepare and re-open the platform file to see whether your change survived.
Runtime lock does nothing
Symptom: screen.lockOrientation('portrait') runs without error but rotation still works.
Likely cause: native configuration allows landscape and the plugin call happened before deviceready, or the WebView doesn't support the API in your platform version. Move the call inside a deviceready handler and log screen.orientation if available. Also confirm the plugin is actually installed (cordova plugin list).
Portrait upside-down rotates
This is expected with portrait on some Android devices that honor sensor-based orientation. If you need a strict upright-only lock on Android, sensorPortrait is often the tighter choice, but actual behavior can vary by device and Android version—test on the devices you support rather than trusting a single value.
iOS iPad behavior surprises you
Symptom: iPad allows certain landscape or multitasking states despite portrait-only plist entries.
Likely cause: iPad multitasking and Stage Manager can impose constraints. If you truly need a rigid portrait experience on iPad, the reliable path is often to restrict the app to iPhone-only compatibility mode or to explicitly design for iPad's conventions, and to verify on an actual iPad rather than a simulator alone.
The lock works in the emulator but not on a device
This usually means the source and built artifacts differ—often because you edited a file under platforms/ that the build regenerated, or you installed a stale build. Rebuild cleanly (cordova clean then cordova build) and side-load the fresh package.
When further work needs a specialist
If your app depends on a third-party native plugin that creates its own activity or view controller and forces unspecified orientation, or if you're building a custom native extension, reconcile orientation at the native layer. That's a native iOS (Objective-C/Swift) or Android (Java/Kotlin) task; if you aren't comfortable reading and modifying the plugin's native source, bring in the plugin's maintainer or a mobile developer rather than layering more JavaScript hacks on top.
Choosing between native config and a runtime plugin
The decision comes down to intent, not preference:
If the entire app should never rotate, use native configuration. It locks earliest, covers splash and native UI, and has no runtime overhead or plugin dependency. If only some screens should allow landscape, leave native orientation permissive and enforce runtime locks per screen, resetting on navigation away. If you inherited a mixed codebase where some screens already call orientation APIs, audit every call site before adding a native lock; otherwise you'll have a native lock fighting a runtime unlock, and the symptom looks like a random bug.
| Goal | Native config | Runtime plugin |
|---|---|---|
| Whole app locked to portrait from launch | Yes, primary method | Not needed |
| Splash and native dialogs also portrait | Yes | No (runs after launch) |
| Per-screen landscape exception | No | Yes |
| Survives platform regeneration | Only via hook | Yes (it's a plugin) |
| Extra dependency | None | Plugin + JS calls |
A pragmatic default for most apps: lock portrait natively on both platforms, skip the plugin entirely, and only introduce runtime orientation control if a specific feature genuinely requires landscape. Fewer moving parts means fewer ways for the lock to break on a device you didn't test.
Checking your work across platforms and versions
Verification isn't glamorous, but it's where orientation locks quietly fail. The checklist that catches most problems:
1: Confirm the source file under platforms/ actually contains your change after cordova prepare. 2: Confirm the built artifact contains it too—inspect the APK's manifest or the built app bundle's plist. 3: Rotate the device physically, not just the simulator, on at least one Android device and one iPhone if you ship both. 4: Test the launch path specifically: cold start, splash visible, then the WebView. Orientation should be portrait throughout. 5: If you added a hook, simulate a teammate's clean checkout (cordova platform rm android, cordova platform add android, cordova prepare) and verify the file still ends up portrait-only.
Keep in mind that Cordova version and platform version matter. The paths shown here (app/src/main/AndroidManifest.xml, cordova-plugin-screen-orientation) match modern Cordova 10–12 projects; very old projects (Cordova 8 and earlier) used platforms/android/AndroidManifest.xml directly and an older plugin generation. If your directories don't match, adjust the paths but keep the same concepts—activity attribute on Android, supported-orientation array on iOS.
FAQ
Does config.xml have an orientation preference I can set? Not one that universally locks orientation on all platforms. The key you may have seen is honored by some platforms (historically Windows/others) but isn't the mechanism for Android or iOS screen locking in modern Cordova. Use the manifest or plist.
Can I lock to landscape instead of portrait? Yes. On Android use android:screenOrientation="landscape" (or sensorLandscape); on iOS replace the portrait string with UIInterfaceOrientationLandscapeLeft/Right. The same layering logic applies.
Why does the app briefly flash landscape on launch before settling? The native window may be created before orientation constraints in the WebView apply, especially if you rely on a runtime plugin call. Native configuration set on the activity from the start avoids this flash; a runtime call inside deviceready does not.
Does locking portrait break the camera or file picker? Generally no. Native picker and camera activities have their own orientation behavior and typically don't inherit the main activity's lock. If a plugin's activity forces landscape, that's a plugin-level issue to reconcile natively.