Touch: touchType property

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

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

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

Specification
Touch Events
# dom-touch-touchtype

Browser compatibility

See also