Skip to content
IndexRequest a UIAboutContact

Swipe to Delete

A list row that slides away when dragged past a threshold, and springs back if released early.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Create a list of four message rows (56px tall, 14px text) inside a 300px wide card. Each row is a foreground element on top of a background element containing the word "Delete" on the right. Use pointer events on the foreground with touch-action pan-y: while dragging left, translate the foreground by the horizontal delta (never right of 0) and fade in the background label proportionally. If on release the drag exceeds 40% of the row width, animate the row off to the left and collapse its height to 0 over 220ms, then remove it from the DOM; otherwise return it to 0 with a 260ms cubic-bezier(.2,.7,.2,1) transition. Rows are focusable (tabindex 0); pressing Delete or Backspace removes the focused row with the same animation. Add a Reset button that restores the list. Under prefers-reduced-motion remove animations.

About this pattern

Definition

A list row that follows the finger or pointer horizontally. Dragging it past a threshold removes it; releasing earlier returns it to its place.

Purpose & UX principles

  • A fast, direct way to remove items from a list on touch devices.
  • Because gestures are hidden, a keyboard alternative is required: focus the row and press Delete.
  • A red label behind the row reveals what the gesture will do while dragging.

Interaction states

  • Rest, dragging (row follows pointer, label fades in), past threshold (label turns solid), removed, focus-visible ring.

Motion specification

  • Following the pointer has no transition; release uses 260ms cubic-bezier(.2,.7,.2,1).
  • Removal slides the row off and collapses its height in 220ms.
  • Reduced motion: removal is instant and the row snaps back without animation.

Responsive behaviour

  • The row fills the list width; the threshold is 40% of the row width.
  • Vertical page scrolling stays possible because the row only captures horizontal movement (touch-action: pan-y).

Code

HTML
<div class="box">
  <ul class="list" id="list"></ul>
  <button class="reset" id="reset" type="button">Reset</button>
</div>

Related patterns

Drag to Reorder

↗
Drag to ReorderGestures & Touch

Toast

↗
ToastFeedback & Notifications

Slide to Confirm

↗
Slide to ConfirmGestures & Touch