AI CSS Animations

Swipe to Reveal Actions Hover

An inbox row that slides left on hover to uncover snooze and archive buttons, like a swipe on a phone. The actions sit behind the row and pop in a beat after it moves.

Also known as: swipe to delete css, list item swipe hint, reveal actions behind row.

Northwind BillingYour October invoice is ready to view.

HTML

<div class="hfx-swipe-actions">
  <div class="hfx-swipe-actions-behind">
    <button aria-label="Snooze"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="8.5"/><path d="M12 7.5V12l3 2"/></svg></button>
    <button aria-label="Archive"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3.5" y="4" width="17" height="4.5" rx="1"/><path d="M5 8.5v10A1.5 1.5 0 0 0 6.5 20h11a1.5 1.5 0 0 0 1.5-1.5v-10M10 12.5h4"/></svg></button>
  </div>
  <div class="hfx-swipe-actions-row">
    <span class="hfx-swipe-actions-avatar" aria-hidden="true">NB</span>
    <span class="hfx-swipe-actions-text"><strong>Northwind Billing</strong><small>Your October invoice is ready to view.</small></span>
    <time>9:41</time>
  </div>
</div>

CSS

.hfx-swipe-actions {
  --c: var(--hfx-color, #3b82f6);
  font-size: var(--hfx-size, 16px);
  position: relative;
  isolation: isolate;
  width: 19em;
  overflow: hidden;
  border-radius: 0.9em;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 0.5em 1.2em -0.6em rgba(15, 23, 42, 0.35);
  font-family: system-ui, sans-serif;
}
.hfx-swipe-actions-behind {
  position: absolute;
  inset: 0;
  z-index: -1;
  display: flex;
  justify-content: flex-end;
  background: color-mix(in srgb, var(--c) 55%, #fff);
}
.hfx-swipe-actions-behind button {
  display: grid;
  place-items: center;
  width: 3.4em;
  padding: 0;
  border: 0;
  background: color-mix(in srgb, var(--c) 55%, #fff);
  color: #fff;
  cursor: pointer;
}
.hfx-swipe-actions-behind button + button { background: var(--c); }
.hfx-swipe-actions-behind svg {
  width: 1.3em;
  height: 1.3em;
  opacity: 0;
  transform: scale(0.4);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease;
}
.hfx-swipe-actions-row {
  display: flex;
  align-items: center;
  gap: 0.75em;
  padding: 0.8em 1em;
  background: #fff;
  box-shadow: 0.5em 0 1em -0.6em rgba(15, 23, 42, 0.45);
  color: #1f2937;
  transition: transform 0.45s cubic-bezier(0.3, 1.25, 0.5, 1);
}
.hfx-swipe-actions-avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 2.3em;
  height: 2.3em;
  border-radius: 50%;
  background: color-mix(in srgb, var(--c) 16%, transparent);
  color: var(--c);
  font-size: 0.85em;
  font-weight: 700;
}
.hfx-swipe-actions-text {
  display: grid;
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}
.hfx-swipe-actions-text small {
  overflow: hidden;
  color: #6b7280;
  font-size: 0.8em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hfx-swipe-actions time {
  align-self: flex-start;
  color: #9ca3af;
  font-size: 0.75em;
}
.hfx-swipe-actions:is(:hover, :focus-within) .hfx-swipe-actions-row { transform: translateX(-6.8em); }
.hfx-swipe-actions:is(:hover, :focus-within) .hfx-swipe-actions-behind svg {
  opacity: 1;
  transform: scale(1);
  transition-delay: 0.12s;
}

@media (prefers-reduced-motion: reduce) {
  .hfx-swipe-actions, .hfx-swipe-actions *, .hfx-swipe-actions::before, .hfx-swipe-actions::after, .hfx-swipe-actions *::before, .hfx-swipe-actions *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

Customizing this snippet

  • Color: set --hfx-color on the element or a parent. Currently previewing #3b82f6.
  • Base size: set --hfx-size. Every other dimension is in em, so the whole thing scales together. Currently previewing 16px.
  • Speed: change the duration on the transition or animation shorthand. Staggered delays are relative, so they keep their rhythm.
  • Reduced motion: the rule at the end of the CSS turns the motion off for people who asked their OS for less of it. Keep it.

Similar hover effects