files/en-us/web/api/window/devicemotion_event/index.md
{{APIRef("Device Orientation Events")}}{{securecontext_header}}
The devicemotion event is fired at a regular interval and indicates the acceleration rate of the device with/without the contribution of the gravity force 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 {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
addEventListener("devicemotion", (event) => { })
ondevicemotion = (event) => { }
A {{domxref("DeviceMotionEvent")}}. Inherits from {{domxref("Event")}}.
{{InheritanceDiagram("DeviceMotionEvent")}}
function handleMotionEvent(event) {
const x = event.accelerationIncludingGravity.x;
const y = event.accelerationIncludingGravity.y;
const z = event.accelerationIncludingGravity.z;
// Do something awesome.
}
window.addEventListener("devicemotion", handleMotionEvent);
{{Specifications}}
{{Compat}}