Touch: touchType property

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

undefined

Basic usage

js
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

See also