Limited support Limited browser support. Check compatibility before use.

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
Accelerometer
Experimental
67
79
67
HTML attribute
allow (accelerometer)
Experimental
66
79
66
DOM API
Accelerometer
Experimental

The Accelerometer() constructor creates a new Accelerometer object which returns the acceleration of the device along all three axes at the time it is read.

67
79
67
x
Experimental

The x read-only property of the Accelerometer interface returns a number specifying the acceleration of the device along its x-axis.

67
79
67
y
Experimental

The y read-only property of the Accelerometer interface returns a number specifying the acceleration of the device along its y-axis.

67
79
67
z
Experimental

The z read-only property of the Accelerometer interface returns a number specifying the acceleration of the device along its z-axis.

67
79
67

The GravitySensor interface of the Sensor APIs provides on each reading the gravity applied to the device along all three axes.

91
91
91

The GravitySensor() constructor creates a new GravitySensor object which provides on each reading the gravity applied to the device along all three axes.

91
91
91

The LinearAccelerationSensor interface of the Sensor APIs provides on each reading the acceleration applied to the device along all three axes, but without the contribution of gravity.

67
79
67

The LinearAccelerationSensor() constructor creates a new LinearAccelerationSensor object which provides on each reading the acceleration applied to the device along all three axes, but without the contribution of gravity.

67
79
67
permission_accelerometer
Experimental

`accelerometer` permission

62
79
62
Other
accelerometer
Experimental

The HTTP Permissions-Policy header accelerometer directive controls whether the current document is allowed to gather information about the acceleration of the device through the Accelerometer interface.

88
88
88
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)

Syntax

JAVASCRIPT
const acl = new Accelerometer({ frequency: 60 });
acl.addEventListener("reading", () => {
  console.log(`Acceleration along the X-axis ${acl.x}`);
  console.log(`Acceleration along the Y-axis ${acl.y}`);
  console.log(`Acceleration along the Z-axis ${acl.z}`);
});

acl.start();

Use cases

  • Using Accelerometer

    The Accelerometer interface of the Sensor APIs provides on each reading the acceleration applied to the device along all three axes.

Cautions

  • Limited browser support. Check compatibility before use.

Implementation notes

  • Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.