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.

Bubbles No
Cancelable No
Interface DeviceMotionEvent
Target DefaultView (window)
Default Action None


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);

Other properties

Property Type Description
acceleration Read only DeviceAcceleration The acceleration of the device. This value has taken into account the effect of gravity and removed it from the figures. This value may not exist if the hardware doesn't know how to remove gravity from the acceleration data.
accelerationIncludingGravity Read only DeviceAcceleration The acceleration of the device. This value includes the effect of gravity, and may be the only value available on devices that don't have a gyroscope to allow them to properly remove gravity from the data.
interval Read only double The interval, in milliseconds, at which the DeviceMotionEvent is fired. The next event will be fired in approximately this amount of time.
rotationRate Read only DeviceRotationRate The rates of rotation of the device about all three axes.


Specification Status
DeviceOrientation Event Specification
The definition of 'DeviceMotion event' in that specification.
Editor's Draft

Browser compatibility

Update compatibility data on GitHub
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
devicemotion event
Chrome Full support YesEdge Full support YesFirefox Full support 6IE ? Opera Full support YesSafari ? WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 6Opera Android No support NoSafari iOS Full support 4.2Samsung Internet Android Full support Yes


Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.
Experimental. Expect behavior to change in the future.

See Also

Document Tags and Contributors

Last updated by: estelle,