Check if touch events are supported Check if 'ontouchstart' exists in window. const supportsTouchEvents = () => window && 'ontouchstart' in window; // Example supportsTouchEvents(); // true Source https://www.30secondsofcode.org/js/s/supports-touch-events