Device orientation events

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

Device orientation events are events that allow you to detect a device's physical orientation, as well as allowing you to detect the device's motion.

Concepts and usage

Mobile devices commonly have sensors such as gyroscopes, compasses, and accelerometers that can enable applications running on the device to detect the device's orientation and motion.

The device orientation events enable you to write web applications that can change their behavior based on the orientation of the user's device, and that can react when the user moves their device.

Some typical features for which you might want to use the device orientation events include:

  • in web-based games, to enable the user to control the motion of characters or objects in the game by tilting and moving the device

  • in mapping applications, to re-orient a map based on the device's position, or to provide turn-by-turn directions that update with the user's movements

  • for gesture recognition — for example, recognizing a "shake" gesture and using it to perform some action such as clearing an input area when the user shakes the device

Note: This API is widely supported on mobile browsers. While some desktop-only browsers may have limitations due to hardware differences, these constraints are rarely significant given the API's primary usage on sensor-equipped devices.

Interfaces

DeviceMotionEvent

Represents changes in the acceleration of a device, as well as the rotation rate.

DeviceMotionEventAcceleration

Represents the amount of acceleration the device is experiencing along all three axes

DeviceMotionEventRotationRate

Represents the rate at which the device is rotating around all three axes.

DeviceOrientationEvent

Represents changes in the physical orientation of a device.

Extensions to other interfaces

devicemotion event

Fired at a regular interval to indicate the amount of physical force of acceleration the device is receiving at that time, and the rate of rotation of the device.

deviceorientation event

Fired when fresh data is available from the device about the current orientation of the device as compared to the Earth coordinate frame.

deviceorientationabsolute event

Fired when absolute device orientation changes.

Specifications

Specification
Device Orientation and Motion

Browser compatibility

api.Window.deviceorientation_event

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
deviceorientation event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Uses a non-standard name.
Has more compatibility info.

api.Window.devicemotion_event

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
devicemotion event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

api.Window.deviceorientationabsolute_event

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
deviceorientationabsolute event

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

api.DeviceOrientationEvent

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
DeviceOrientationEvent
DeviceOrientationEvent() constructor
absolute
alpha
beta
gamma
requestPermission() static method
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

api.DeviceMotionEvent

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
DeviceMotionEvent
DeviceMotionEvent() constructor
acceleration
accelerationIncludingGravity
interval
requestPermission() static method
Experimental
rotationRate

Legend

Tip: you can click/tap on a cell for more information.

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

api.DeviceMotionEventAcceleration

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
DeviceMotionEventAcceleration
x
y
z

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

api.DeviceMotionEventRotationRate

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
DeviceMotionEventRotationRate
alpha
beta
gamma

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also