Touch Gestures Snippets — Free HTML CSS JS Swipe & Touch Gesture Examples

115 snippets tagged Touch Gestures · Live preview · Exports to React, Vue, Angular & Tailwind

What's included

Features

Swipe-to-dismiss and swipe-to-action cards with velocity-aware thresholds
Pull-to-refresh with resistance curve and release-to-trigger feedback
Pinch-zoom and pan for images, with bounds clamping
Long press with a progress indicator and a cancel-on-move path
touch-action and passive-listener handling so gestures never block scrolling

About this tag

Touch Gestures Snippets — 115 Free Swipe & Touch Gesture Examples

Touch interfaces are built from a small vocabulary — swipe, drag, pinch, long press, double tap — and each one has a threshold and a feel that has to be tuned rather than guessed. These snippets implement that vocabulary with pointer events, so the same code path serves mouse, touch and stylus.

They follow the platform conventions people already expect: a card that follows the finger and snaps past a distance threshold, a sheet that can be flung closed, a long press that gives feedback before it fires, and gestures that stop fighting the browser's own scrolling.

One event model for every input type

Pointer events unify mouse, touch and stylus behind a single API, carrying pressure and tilt data when the hardware provides it and supporting pointer capture — the mechanism that keeps a drag tracking correctly even after the finger moves outside the original element's bounds. Building on pointer events instead of the older, touch-specific TouchEvent API is what lets every snippet here behave identically whether it is tested with a mouse on a laptop or a thumb on a phone.

Distance and velocity together

A swipe-to-dismiss or swipe-to-action gesture commits based on two signals, not one: how far the pointer travelled, and how fast it was moving at release. Distance alone makes a fast, short flick feel unresponsive since it falls short of the threshold; velocity alone makes a slow, deliberate drag fail to register. Combining them — commit past a fraction of the element's width, or on a fast release even short of that — is what makes the gesture feel right under both a hurried flick and a careful drag.

Resistance and release, not just movement

Pull-to-refresh, sheet-drag and similar gestures use a resistance curve rather than a raw 1:1 pixel mapping, so the further something is dragged past its natural range the harder it becomes to pull further. Combined with a spring-back animation when the pointer releases below the trigger threshold, this is what makes a gesture feel physical instead of just tracking a coordinate.

Not fighting the browser's own scrolling

A custom gesture and native scrolling compete for the same pointer input unless told otherwise. Setting touch-action explicitly — none for a fully custom gesture, pan-y when only horizontal movement should be intercepted — tells the browser up front which axis to leave alone, which is more reliable than calling preventDefault inside a touch handler, since that call does nothing in a passive listener.

Real-world uses

Common Use Cases

Mobile app screens
Swipeable cards and draggable sheets are what make a web view feel native rather than transplanted.
Inbox and list actions
Swipe-to-archive and swipe-to-delete put the two common actions one gesture away from every row.
Image galleries and viewers
Pinch to zoom and drag to pan are the two gestures users try first on any image, on every platform.
Reaction and confirmation gestures
Double-tap to like and long-press to confirm add depth without adding buttons to a crowded screen.

Got questions?

Frequently Asked Questions

Pointer events. They cover mouse, touch and pen through one API, carry pressure and tilt when available, and support pointer capture — which is what keeps a drag tracking correctly when the finger leaves the element. Touch events are only needed for legacy support.

Because the browser starts its own scroll unless you tell it not to. Set touch-action on the element — touch-action: none for a fully custom gesture, or pan-y when you only handle horizontal swipes — rather than calling preventDefault, which does not work in a passive listener anyway.

Combine distance and velocity: commit if the gesture travelled more than roughly a third of the element width, or if it was moving fast enough at release even over a short distance. Distance alone makes fast flicks feel unresponsive; velocity alone makes slow deliberate drags fail.

No. Every snippet is plain HTML, CSS and vanilla JavaScript that runs in any page — a static file, a WordPress theme, a Rails view, anything. When you do want a framework version, the editor exports each snippet as a React component, a React + Tailwind component, a standalone Tailwind HTML file, a Vue 3 single-file component or an Angular standalone component.

Yes — copy, modify and ship them in personal or commercial work, with no attribution required and no licence to track.

Yes. Every snippet opens in a live editor with separate HTML, CSS and JS panels and a preview that updates as you type. Check it at mobile, tablet and desktop widths, then copy the code or export it in your framework of choice.