MDN self-hosted library · e01.org

Touch: touchType property

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

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,
);