Copyright © 2025 W3C® (MIT, ERCIM, Keio, Beihang). W3C liability, trademark and permissive document license rules apply.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
If you have comments for this spec, please send them to public-webapps@w3.org with a Subject: prefix of[gamepad]
. See
Bugzilla for this specification's open bugs.
This document was published by the Web Platform Working Group as an Editor's Draft.
Comments regarding this document are welcome. Please send them to public-webapps@w3.org (archives).
Publication as an Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 1 March 2019 W3C Process Document.
The Gamepad API provides a tightly scoped interface to gamepad devices and is focused on the most common elements of those devices, namely axis and button inputs. It specifically excludes support for more complex devices (e.g., those that do motion tracking or haptic feedback).
However, some uses of gamepads (e.g., those paired with Virtual Reality headsets) rely heavily on those more advanced features. This supplemetary spec describes extensions to the base API to accommodate those use cases. If they prove to be broadly useful, the hope is that they will be eventually merged into the main spec.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MAY and MUST in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
GamepadHand
Enum
This enum defines the set of possible hands a gamepad may be held by.
WebIDLenumGamepadHand
{ "", /* unknown, both hands, or not applicable */ "
left
", "right
" };
""
(the empty string)
left
right
GamepadPose
Interface
This interface defines the gamepad's position, orientation, velocity, and acceleration.
WebIDL[Exposed=Window] interfaceGamepadPose
{ readonly attribute booleanhasOrientation
; readonly attribute booleanhasPosition
; readonly attribute Float32Array?position
; readonly attribute Float32Array?linearVelocity
; readonly attribute Float32Array?linearAcceleration
; readonly attribute Float32Array?orientation
; readonly attribute Float32Array?angularVelocity
; readonly attribute Float32Array?angularAcceleration
; };
hasOrientation
hasOrientation
attribute MUST return whether the
gamepad is capable of tracking its orientation.
hasPosition
hasPosition
attribute MUST return whether the
gamepad is capable of tracking its position.
position
Position of the gamepad as a 3D vector, given in meters from an origin point, which is determined by the gamepad hardware and MAY be the position of the gamepad when first polled if no other reference point is available. The coordinate system uses these axis definitions, assuming the user is holding the gamepad in the forward orientation:
MUST be null
if the gamepad is incapable of providing
positional data. When not null
, MUST be a
three-element array.
linearVelocity
null
if the sensor is incapable of providing linear
velocity. When not null
, MUST be a three-element array.
linearAcceleration
null
if the sensor is incapable of providing linear
acceleration. When not null
, MUST be a three-element
array.
orientation
[0, 0, 0, 1]
is considered to be forward
.
The forward direction MUST be determined by the gamepad hardware. The
forward direction MAY be the orientation of the hardware when it was
first polled if no other reference orientation is available. If the
sensor is incapable of providing orientation data, the orientation
MUST be null
. When not null
, the
orientation
MUST be a four-element array.
angularVelocity
null
if the sensor is incapable of providing angular
velocity. When not null
, the
angularVelocity
MUST be a three-element array.
angularAcceleration
null
if the sensor is incapable of providing angular
acceleration. When not null
,
angularAcceleration
MUST be a three-element array.
Gamepad
Interface
This partial interface supplements the Gamepad interface described in the main Gamepad spec.
WebIDLpartial interfaceGamepad
{ readonly attribute GamepadHandhand
; readonly attribute FrozenArray<GamepadHapticActuator>hapticActuators
; readonly attribute GamepadPose?pose
; };
Instances of Gamepad
are created with the internal slots described
in the following table:
Internal slot | Initial value | Description (non-normative) |
---|---|---|
[[hand]] |
undefined
|
Indicates the hand the controller is held in. |
[[hapticActuators]] |
undefined
|
List of all the haptic actuators in the gamepad. |
[[pose]] |
null
|
The current pose of the gamepad. |
hand
GamepadHand
, that indicates which hand the
controller is being held in or is most likely to be held in.
hapticActuators
GamepadHapticActuator
s in the gamepad. The same
object MUST be returned until the user agent needs to return
different values (or values in a different order).
pose
GamepadPose
of the gamepad, if supported by the
hardware. Includes position, orientation, velocity, and acceleration.
If the hardware cannot supply any pose values, MUST be set to null
.
This section supplements the Receiving inputs section of the main Gamepad specification.
Gamepad
This section supplements the Constructing
a Gamepad
section of the main Gamepad specification.
GamepadHapticActuator
Interface
This partial interface supplements the GamepadHapticActuator
interface described in the main Gamepad spec.
WebIDL[Exposed=Window] partial interfaceGamepadHapticActuator
{ Promise<boolean>pulse
(double value, double duration); };
pulse
()
applies a value to the
actuator for duration milliseconds. The value
passed to pulse()
is clamped to limits defined by the
actuator type. The returned Promise will resolve true
once the pulse has completed.
Repeated calls to pulse()
override the previous
values.