--- title: Accelerometer slug: Web/API/Accelerometer translation_of: Web/API/Accelerometer ---
{{APIRef("Generic Sensor API")}}

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

To use this sensor, the user must grant permission to the 'accelerometer', device sensor through the Permissions API.

If a feature policy blocks the use of a feature, it is because your code is inconsistent with the policies set on your server. This is not something that would ever be shown to a user. See {{httpheader('Feature-Policy')}} for implementation instructions.

Constructor

{{domxref("Accelerometer.Accelerometer()")}}
Creates a new Accelerometer object.

Properties

{{domxref('Accelerometer.x')}} {{readonlyinline}}
Returns a double containing the acceleration of the device along the device's x axis.
{{domxref('Accelerometer.y')}} {{readonlyinline}}
Returns a double containing the acceleration of the device along the device's y axis.
{{domxref('Accelerometer.z')}} {{readonlyinline}}
Returns a double containing the acceleration of the device along the device's z axis.

Example

Acceleration is typically read in the {{domxref('Sensor.onreading')}} event callback. In the example below this occurs sixty times a second.

let accelerometer = new Accelerometer({frequency: 60});

accelerometer.addEventListener('reading', e => {
  console.log("Acceleration along the X-axis " + accelerometer.x);
  console.log("Acceleration along the Y-axis " + accelerometer.y);
  console.log("Acceleration along the Z-axis " + accelerometer.z);
});
accelerometer.start();

Specifications

Specification Status Comment
{{SpecName('Generic Sensor')}} {{Spec2('Generic Sensor')}} Defines sensors in general.
{{SpecName('Accelerometer','#accelerometer-interface','Accelerometer')}} {{Spec2('Accelerometer')}}  

Browser compatibility

{{Compat("api.Accelerometer")}}