
Hammer.js
A JavaScript library that detects touch gestures like tap, press, and swipe on web elements.
- Stars
- 24.3k
- Forks
- 2.5k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 10 months ago
- Type
- Library
What it is
Hammer.js is a JavaScript library that listens for touch gestures on a web page element and reports them as events, such as press, tap, double tap, and swipe. Developers attach it to an element and then respond to those gestures in their own code. It is installed through npm, Yarn, or a CDN.
- Make an element expand or toggle when it is pressed
- Detect a double tap on an image or card
- Create a custom recognizer, such as a triple tap, and respond to it
- Add swipe handling to a touch-friendly interface
Great for
- Web developers adding touch interactions to a website or web app
- Developers who want gesture events without writing low-level touch handling
- Projects that need quick-start gestures like press, tap, or double tap
Not ideal for
- People who are not writing code, since it is a library that must be integrated into a web page
- Projects needing custom gesture logic beyond what the README describes, since the README covers only basic recognizers and a triple-tap example
- Teams who need up-to-date documentation in the README itself, since the README points to an external documentation site for full details
How to get it
- 1
Install with a package manager
You'll need: Node.js (for npm or Yarn installs)
Install with npm
npm install --save hammerjsInstall with Yarn
yarn add hammerjs - 2
Run it
- Install the library with npm or Yarn, or include it from the CDN
- Select an element in your page with document.querySelector
- Create a new Hammer instance on that element
- Subscribe to an event such as 'press' with hammer.on('press', handler)
- 3
Get the most out of it
- Use the quick-start events press, tap, and doubletap for common interactions
- Create a custom recognizer with new Hammer.Tap and a taps count for gestures like triple tap
- Use a Hammer.Manager and manager.add() to combine recognizers on one element
- Check the official documentation at hammerjs.github.io for the full list of events
Downloads
Strengths
- Simple API: create an instance on an element and subscribe to events with on()
- Available through npm, Yarn, or a CDN
- MIT licensed and widely used, with a large number of GitHub stars
Trade-offs
- The README is short and refers to external documentation for the full list of events and options
- The README describes detecting gestures; its examples cover press, tap, double tap, and swipe, while pan, pinch, and rotate example links are empty
- Its focus is browser touch input, so it does not cover non-web platforms
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.