Device orientation events
The DeviceMotionEvent interface of the Device Orientation Events provides web developers with information about the speed of changes for the device's position and orientation.
Event DeviceMotionEvent
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 31 | 12 | 6 | 17 | 31 | 4.2 | |
| The acceleration read-only property of the DeviceMotionEvent interface returns the acceleration recorded by the device, in meters per second squared (m/s²). This value does not include the effect of the gravitational force, in contrast to DeviceMotionEvent.accelerationIncludingGravity. | 31 | 12 | 6 | 17 | 31 | 4.2 |
| The accelerationIncludingGravity read-only property of the DeviceMotionEvent interface returns the amount of acceleration recorded by the device, in meters per second squared (m/s²). Unlike DeviceMotionEvent.acceleration which compensates for the influence of gravity, its value is the sum of the acceleration of the device as induced by the user and an… | 31 | 12 | 6 | 17 | 31 | 4.2 |
| The DeviceMotionEvent() constructor creates a new DeviceMotionEvent object. | 59 | 14 | 29 | | 59 | |
| The interval read-only property of the DeviceMotionEvent interface returns the interval, in milliseconds, at which data is obtained from the underlying hardware. You can use this to determine the granularity of motion events. | 31 | 12 | 6 | 17 | 31 | 4.2 |
requestPermission_static Experimental The requestPermission() static method of the DeviceMotionEvent interface requests the user's permission to access device motion data from the accelerometer and gyroscope sensors. This method requires transient activation, meaning that it must be triggered by a UI event such as a button click. | | | | | | 14.5 |
| The rotationRate read-only property of the DeviceMotionEvent interface returns the rate at which the device is rotating around each of its axes in degrees per second. | 31 | 12 | 6 | 17 | 31 | 4.2 |
| The DeviceMotionEventAcceleration interface of the Device Orientation Events provides information about the amount of acceleration the device is experiencing along all three axes. | 31 | 12 | 6 | | 31 | 4.2 |
| The x read-only property of the DeviceMotionEventAcceleration interface indicates the amount of acceleration that occurred along the X axis in a DeviceMotionEventAcceleration object. | 31 | 12 | 6 | | 31 | 4.2 |
| The y read-only property of the DeviceMotionEventAcceleration interface indicates the amount of acceleration that occurred along the Y axis in a DeviceMotionEventAcceleration object. | 31 | 12 | 6 | | 31 | 4.2 |
| The z read-only property of the DeviceMotionEventAcceleration interface indicates the amount of acceleration that occurred along the Z axis in a DeviceMotionEventAcceleration object. | 31 | 12 | 6 | | 31 | 4.2 |
| A DeviceMotionEventRotationRate interface of the Device Orientation Events provides information about the rate at which the device is rotating around all three axes. | 31 | 12 | 6 | | 31 | 4.2 |
| The alpha read-only property of the DeviceMotionEventRotationRate interface indicates the rate of rotation around the Z axis, in degrees per second. | 31 | 12 | 6 | | 31 | 4.2 |
| The beta read-only property of the DeviceMotionEventRotationRate interface indicates the rate of rotation around the X axis, in degrees per second. | 31 | 12 | 6 | | 31 | 4.2 |
| The gamma read-only property of the DeviceMotionEventRotationRate interface indicates the rate of rotation around the Y axis, in degrees per second. | 31 | 12 | 6 | | 31 | 4.2 |
| The DeviceOrientationEvent interface of the Device Orientation Events provides web developers with information from the physical orientation of the device running the web page. | 7 | 12 | 6 | 17 | 18 | 4.2 |
| The absolute read-only property of the DeviceOrientationEvent interface indicates whether or not the device is providing orientation data absolutely (that is, in reference to the Earth's coordinate frame) or using some arbitrary frame determined by the device. See Orientation and motion data explained for details. | 7 | 12 | 6 | 17 | 18 | |
| The alpha read-only property of the DeviceOrientationEvent interface returns the rotation of the device around the Z axis; that is, the number of degrees by which the device is being twisted around the center of the screen. See Orientation and motion data explained for details. | 7 | 12 | 6 | 17 | 18 | 4.2 |
| The beta read-only property of the DeviceOrientationEvent interface returns the rotation of the device around the X axis; that is, the number of degrees, ranged between -180 and 180, by which the device is tipped forward or backward. See Orientation and motion data explained for details. | 7 | 12 | 6 | 17 | 18 | 4.2 |
| The DeviceOrientationEvent() constructor creates a new DeviceOrientationEvent object. | 59 | 14 | 17 | | 59 | |
| The gamma read-only property of the DeviceOrientationEvent interface returns the rotation of the device around the Y axis; that is, the number of degrees, ranged between -90 and 90, by which the device is tilted left or right. See Orientation and motion data explained for details. | 7 | 12 | 6 | 17 | 18 | 4.2 |
requestPermission_static Experimental The requestPermission() static method of the DeviceOrientationEvent interface requests the user's permission to access device orientation data from the accelerometer and gyroscope sensors. It can also request permission to access magnetometer data when absolute orientation is needed. This method requires transient activation, meaning that it must be… | | | | | | 14.5 |
| 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. | 31 | 12 | 6 | 17 | 31 | 4.2 |
| The deviceorientation event is fired when fresh data is available from an orientation sensor about the current orientation of the device as compared to the Earth coordinate frame. This data is gathered from a magnetometer inside the device. | 7 | 12 | 6 | 17 | 18 | 4.2 |
| The deviceorientationabsolute event is fired when absolute device orientation changes. | 50 | 79 | 110 | | 50 | |
- The `DeviceMotionEventAcceleration` interface is supported, but not exposed on the `Window` scope.
- The `DeviceMotionEventAcceleration` interface is supported, but not exposed on the `Window` scope.
- Before version 50, Chrome provided absolute values instead of relative values for this event. Developers still needing absolute values may use the `deviceorientationabsolute` event.
- Firefox 3.6, 4, and 5 supported `mozOrientation` instead of the standard DeviceOrientationEvent interface.
- Before version 50, Chrome Android provided absolute values instead of relative values for this event. Developers still needing absolute values may use the `deviceorientationabsolute` event.
- This feature was removed in a later browser version (6)
- Previously available under a different name: mozOrientation (3.6)
Syntax
window.addEventListener("devicemotion", (event) => {
console.log(`${event.acceleration.x} m/s2`);
}); Use cases
-
Using Device orientation events
The DeviceMotionEvent interface of the Device Orientation Events provides web developers with information about the speed of changes for the device's position and orientation.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.