Environment API
App Bridge isn't versioned with Polaris. App Bridge APIs and web components are identical in every App Home reference version.
App Bridge isn't versioned with Polaris. App Bridge APIs and web components are identical in every App Home reference version.
The Environment API provides access to information about the platform your app is running on. Use it to detect whether the app is embedded in the Shopify admin, running on Shopify Mobile, or running on Shopify POS.
Anchor to Use casesUse cases
- Platform detection: Determine whether your app is running on mobile, desktop, or POS.
- Responsive behavior: Adapt UI layout and features based on the current environment.
- Embedded context: Check whether the app is running in an embedded context within the Shopify admin.
- Device-specific features: Enable or disable features based on device capabilities like camera access or printing.
Anchor to Safe area insetsSafe area insets
App Bridge automatically sets a CSS custom property, --shopify-safe-area-inset-bottom, on the document. This property provides the exact pixel value of host UI overlaying the bottom of your app, such as the Sidekick bar, or navigation controls on mobile. It applies wherever your app runs, including desktop and mobile web, and it defaults to 0px when no overlay is present.
App Bridge also adds an invisible spacer at the end of the <body> element: a body::after pseudo-element that's as tall as the overlay. The spacer lets in-flow content scroll above the overlay, so most apps work correctly without any changes. App Bridge doesn't pad the <body> element itself, so its computed padding-bottom stays 0px. If your app scrolls inside its own container instead of the page, then add var(--shopify-safe-area-inset-bottom, 0px) to the bottom padding of that container.
The spacer doesn't move elements that use position: fixed, such as sticky footers or floating action buttons. Use var(--shopify-safe-area-inset-bottom, 0px) for them:
- For a floating element, such as a floating action button, add the variable to its
bottomoffset to position it above the overlay. - For a full-width bar, such as a sticky footer, keep
bottom: 0and add the variable to itspadding-bottom. The bar's background reaches the bottom edge, and its content stays above the overlay. If you move a full-width bar up with thebottomoffset instead, then page content scrolls into view in the gap below the bar.
Anchor to PropertiesProperties
The environment API is available on the shopify global. All properties are synchronous booleans.
- Anchor to embeddedembeddedembeddedbooleanboolean
Whether the app is embedded in the Shopify admin.
- Anchor to intentintentintentbooleanboolean
Whether the app is running as an intent.
- Anchor to mobilemobilemobilebooleanboolean
Whether the app is running inside the Shopify Mobile app.
- Anchor to posposposbooleanboolean
Whether the app is running inside the Shopify POS app.
js
Examples
Detect the current platform
Description
Read the environment object to see which platform your app is running on. Each property is a boolean that indicates whether a specific condition is true.
js
shopify.environment; // => { mobile: false, embedded: true, pos: false }Adapt your UI based on the platform
Description
Check individual environment properties to adapt your app's behaviour to the current platform. In this example, your app shows a print button only on mobile devices where App Bridge handles printing through the native app.
js
const mobile = shopify.environment.mobile; if (mobile) { document.getElementById('print-button').style.display = 'block'; } else { document.getElementById('print-button').style.display = 'none'; }Position elements above host UI overlays
Description
App Bridge sets the `--shopify-safe-area-inset-bottom` CSS custom property to the height of host UI overlaying the bottom of your app, such as the Sidekick bar, or navigation controls on mobile. Add this variable to the `bottom` offset of a floating element to position it above the overlay. For a full-width bar, keep `bottom: 0` and add the variable to its `padding-bottom`, so the bar reaches the bottom edge and its content stays above the overlay. The variable applies wherever your app runs, and defaults to `0px` when no overlay is present.
css
.my-floating-button { position: fixed; bottom: calc(16px + var(--shopify-safe-area-inset-bottom, 0px)); right: 16px; } .my-sticky-footer { position: fixed; bottom: 0; right: 0; left: 0; padding: 12px 16px calc(12px + var(--shopify-safe-area-inset-bottom, 0px)); }