Window: devicemotion event

The devicemotion event is fired at a regular interval and indicates the amount of physical force of acceleration the device is receiving at that time. It also provides information about the rate of rotation, if available.

This event is not cancelable and does not bubble.


Use the event name in methods like addEventListener(), or set an event handler property.

addEventListener('devicemotion', event => { });

ondevicemotion = event => { };

Event type

Event properties

DeviceMotionEvent.accelerationRead only

An object giving the acceleration of the device on the three axis: x, y, and z. Acceleration is expressed in m/s².

DeviceMotionEvent.accelerationIncludingGravityRead only

An object giving the acceleration of the device on the three axis: x, y, and z with the effect of gravity. Acceleration is expressed in m/s².

DeviceMotionEvent.rotationRateRead only

An object giving the rate of change of the device's orientation on the three orientation axis: alpha, beta and gamma. Rotation rate is expressed in degrees per seconds.

DeviceMotionEvent.intervalRead only

A number representing the interval of time, in milliseconds, at which data is obtained from the device.


function handleMotionEvent(event) {

    var x = event.accelerationIncludingGravity.x;
    var y = event.accelerationIncludingGravity.y;
    var z = event.accelerationIncludingGravity.z;

    // Do something awesome.

window.addEventListener("devicemotion", handleMotionEvent, true);


DeviceOrientation Event Specification
# devicemotion
DeviceOrientation Event Specification
# ref-for-dom-window-ondevicemotion

Browser compatibility

BCD tables only load in the browser

See also