coderef

AccelerometerLimited availability

The Accelerometer, LinearAccelerationSensor and GravitySensor APIs read the acceleration applied to a device in three dimensions, either including the effect of gravity, without its effect, or only its effect, respectively.

Not yet supported in all major browsers — check the table and provide a fallback.

Browser support

DesktopChrome
1–90Not supported
91+Supportedsince May 25, 2021
Current: 155
Edge
12–90Not supported
91+Supportedsince May 27, 2021
Current: 154
Firefox
✕Not supportedup to 157
Current: 157
Safari
✕Not supportedup to 27
Current: 27
MobileChrome Android
18–90Not supported
91+Supportedsince May 25, 2021
Current: 155
Firefox Android
✕Not supportedup to 157
Current: 157
Safari iOS
✕Not supportedup to 27
Current: 27

How to use

Not supported in Firefox, Safari, Firefox Android, Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.

Example

Full syntax and examples are on MDN: Accelerometer.

Feature detection

JS · check before using
if ("Accelerometer" in globalThis) {
  // Accelerometer is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (12). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Accelerometer6779✕✕67✕✕
Accelerometer.Accelerometer6779✕✕67✕✕
Accelerometer.x6779✕✕67✕✕
Accelerometer.y6779✕✕67✕✕
Accelerometer.z6779✕✕67✕✕
GravitySensor9191✕✕91✕✕
GravitySensor.GravitySensor9191✕✕91✕✕
LinearAccelerationSensor6779✕✕67✕✕
LinearAccelerationSensor.LinearAccelerationSensor6779✕✕67✕✕
Permissions.permission_accelerometer6279✕✕62✕✕
iframe.allow.accelerometer6679✕✕66✕✕
http.headers.Permissions-Policy.accelerometer8888✕✕88✕✕