MDN self-hosted library · e01.org

Touch: touchType property

Touch Events

Open notebook · 1 cells web-api-instance-property upstream source

Touch Events

The touchType read-only property of the Touch interface returns the type of device that triggered the touch, such as a stylus, or direct touch from a finger.

Value

A string from the TouchType enumeration. Possible values are:

  • "direct"
  • : The touch was made by a direct contact, such as a finger on the screen.
  • "stylus"
  • : The touch was made using a stylus or pen device.

Example

Basic usage

someElement.addEventListener(
  "touchstart",
  (event) => {
    for (const touch of event.changedTouches) {
      console.log(`Touch type: ${touch.touchType}`);

      if (touch.touchType === "stylus") {
        // Handle stylus-specific input, such as altitude and azimuth angles.
        console.log(`altitudeAngle: ${touch.altitudeAngle}`);
        console.log(`azimuthAngle: ${touch.azimuthAngle}`);
      }
    }
  },
  false,
);

Specifications

Browser compatibility

See also