How to install Hammer.js


Hammer.js is a open-source library that can recognize gestures made by touch, mouse and pointerEvents. It doesn’t have any dependencies, and it’s small, only 7.34 kB minified + gzipped!


You can download the latest version of Hammer.js from the GitHub releases or use a Hammer.js CDN.

Cloning a repository

You can clone a repository from to your local computer.
Cloning with HTTPS URLs
git clone
Cloning with SSH URLs
git clone [email protected]:hammerjs/hammer.js.git
Cloning with GitHub CLI
gh repo clone hammerjs/hammer.js

Install via NPM package

Run the following command to locally install the package and its dependencies with NPM.
Downloading and installing packages locally
npm i hammerjs
npm install hammerjs
yarn add hammerjs
Downloading and installing packages globally
npm i -g hammerjs
yarn global add hammerjs
Install Specific Version of a Package
npm install [email protected]
bower install hammerjs


Code 1: - It’s easy to use, just include the library and create a new instance.

var hammertime = new Hammer(myElement, myOptions);
hammertime.on('pan', function(ev) {

Code 2: - hammer.js has a quick start option for gestures it already recognizes.

// Get a reference to an element.
var square = document.querySelector('.square');

// Create an instance of Hammer with the reference.
var hammer = new Hammer(square);

// Subscribe to a quick start event: press, tap, or doubletap.
// For a full list of quick start events, read the documentation.
hammer.on('press', function(e) {'expand');
  console.log("You're pressing me!");