Double Tap to Like
Double tap or double click a photo to like it, with a heart that pops in at the tap point.
AI prompt
Create a photo card 280x180px (gradient placeholder) with a like button below it. Listen for pointerup on the photo: if a second pointerup happens within 300ms and within 30px of the first, treat it as a double tap. On a double tap, create a heart SVG at the tap position that animates scale 0.4 to 1.1 to 1 and fades out over 700ms with cubic-bezier(.3,1.4,.5,1), then remove it; also set the liked state to true if not already liked. The separate like button (44px, aria-pressed, aria-label "Like") toggles the liked state; when liked the heart is filled red and pulses scale 1 to 1.25 to 1 in 220ms. Display a like count that increments or decrements and announce it in an aria-live region. Prevent text selection and the native double-tap zoom on the photo with touch-action manipulation. Under prefers-reduced-motion use a 300ms fade without scaling.About this pattern
Definition
A gesture where two quick taps on content register a like. A heart animates at the position of the second tap, and a regular like button stays available.
Purpose & UX principles
- A quick, delightful shortcut popularised by photo feeds.
- It is a shortcut only: the same action must exist as a labelled button with
aria-pressed. - Double tapping never removes a like; it only adds one, so people cannot undo by accident.
Interaction states
- Not liked, liked (filled heart, pressed), heart-pop animation, focus-visible on the button.
Motion specification
- Pop heart: scale 0.4 to 1.1 to 1 with fade out, 700ms cubic-bezier(.3,1.4,.5,1).
- Button heart: a 220ms scale pulse.
- Reduced motion: the pop is replaced by a 300ms fade without scaling.
Responsive behaviour
- Works with touch and mouse. Two taps within 300ms and 30px count as a double tap.
- The like button is at least 44px.
Code
<div class="card">
<div class="photo" id="photo" aria-label="Photo, double tap to like"></div>
<div class="bar"><button class="like" id="like" aria-pressed="false" aria-label="Like"><svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M12 21s-7-4.6-9.5-9C.9 8.5 3 5 6.5 5c2 0 3.6 1.1 5.5 3 1.9-1.9 3.5-3 5.5-3C21 5 23.100 8.500 21.500 12 19 16.400 12 21 12 21z"/></svg></button><span id="cnt" aria-live="polite">128 likes</span></div>
</div>:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
.card{width:min(280px,100%);background:var(--surface);border:1px solid var(--line);border-radius:14px;overflow:hidden}
.photo{position:relative;height:160px;background:linear-gradient(135deg,#dcdcd7,#b9b9b3);touch-action:manipulation;user-select:none;-webkit-user-select:none;overflow:hidden}
.bar{display:flex;align-items:center;gap:10px;padding:4px 8px}
.like{width:44px;height:44px;border-radius:50%;border:0;background:none;cursor:pointer;display:grid;place-items:center;color:var(--text)}
.like svg{fill:none;stroke:currentColor;stroke-width:1.8;stroke-linejoin:round}
.like:hover{background:var(--bg)}
.like:focus-visible{outline:2px solid var(--accent)}
.like[aria-pressed=true] svg{fill:#e11d48;stroke:#e11d48}
.like.pulse svg{animation:pu .22s ease-out}
@keyframes pu{50%{transform:scale(1.25)}}
#cnt{font-size:13px;color:var(--muted)}
.pop{position:absolute;width:64px;height:64px;margin:-32px 0 0 -32px;pointer-events:none;animation:pop .7s cubic-bezier(.3,1.4,.5,1) forwards}
.pop svg{width:100%;height:100%;fill:#e11d48}
@keyframes pop{0%{transform:scale(.4);opacity:0}25%{transform:scale(1.1);opacity:1}60%{transform:scale(1);opacity:1}100%{transform:scale(1);opacity:0}}
@media (prefers-reduced-motion:reduce){.pop{animation:fade .3s forwards}.like.pulse svg{animation:none}@keyframes fade{0%{opacity:0}30%{opacity:1}100%{opacity:0}}}const photo=document.getElementById('photo'),like=document.getElementById('like'),cnt=document.getElementById('cnt');
let liked=false,n=128;
function set(v){liked=v;n+=v?1:-1;like.setAttribute('aria-pressed',String(v));cnt.textContent=n+' likes';like.classList.remove('pulse');void like.offsetWidth;like.classList.add('pulse');}
like.addEventListener('click',()=>set(!liked));
let last=0,lx=0,ly=0;
photo.addEventListener('pointerup',e=>{const now=performance.now();
if(now-last<300&&Math.hypot(e.clientX-lx,e.clientY-ly)<30){last=0;const r=photo.getBoundingClientRect(),h=document.createElement('div');h.className='pop';h.style.left=(e.clientX-r.left)+'px';h.style.top=(e.clientY-r.top)+'px';h.innerHTML='<svg viewBox="0 0 24 24"><path d="M12 21s-7-4.600-9.500-9C.900 8.500 3 5 6.500 5c2 0 3.600 1.100 5.500 3 1.900-1.900 3.500-3 5.500-3C21 5 23.100 8.500 21.500 12 19 16.400 12 21 12 21z"/></svg>';photo.append(h);setTimeout(()=>h.remove(),720);if(!liked)set(true);}
else{last=now;lx=e.clientX;ly=e.clientY;}});One complete HTML file. Save it and open it in a browser.
<!doctype html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Double Tap to Like — demo</title>
<style>
:root{--bg:#F1F1EF;--surface:#fff;--surface-2:#F7F7F5;--line:#E0E0DC;--text:#171717;--muted:#6f6f6f;--accent:#171717;--accent-ink:#fff;--danger:#d92d20}
*{box-sizing:border-box;margin:0}
html,body{height:100%}body{background:var(--bg);color:var(--text);font:15px/1.5 -apple-system,BlinkMacSystemFont,'Segoe UI',Inter,Roboto,sans-serif;-webkit-font-smoothing:antialiased}.stage{min-height:100%;display:grid;place-items:center;padding:24px}button,input,select,textarea{font-family:inherit}@media (prefers-reduced-motion:reduce){html{scroll-behavior:auto}}
.card{width:min(280px,100%);background:var(--surface);border:1px solid var(--line);border-radius:14px;overflow:hidden}
.photo{position:relative;height:160px;background:linear-gradient(135deg,#dcdcd7,#b9b9b3);touch-action:manipulation;user-select:none;-webkit-user-select:none;overflow:hidden}
.bar{display:flex;align-items:center;gap:10px;padding:4px 8px}
.like{width:44px;height:44px;border-radius:50%;border:0;background:none;cursor:pointer;display:grid;place-items:center;color:var(--text)}
.like svg{fill:none;stroke:currentColor;stroke-width:1.8;stroke-linejoin:round}
.like:hover{background:var(--bg)}
.like:focus-visible{outline:2px solid var(--accent)}
.like[aria-pressed=true] svg{fill:#e11d48;stroke:#e11d48}
.like.pulse svg{animation:pu .22s ease-out}
@keyframes pu{50%{transform:scale(1.25)}}
#cnt{font-size:13px;color:var(--muted)}
.pop{position:absolute;width:64px;height:64px;margin:-32px 0 0 -32px;pointer-events:none;animation:pop .7s cubic-bezier(.3,1.4,.5,1) forwards}
.pop svg{width:100%;height:100%;fill:#e11d48}
@keyframes pop{0%{transform:scale(.4);opacity:0}25%{transform:scale(1.1);opacity:1}60%{transform:scale(1);opacity:1}100%{transform:scale(1);opacity:0}}
@media (prefers-reduced-motion:reduce){.pop{animation:fade .3s forwards}.like.pulse svg{animation:none}@keyframes fade{0%{opacity:0}30%{opacity:1}100%{opacity:0}}}
</style></head>
<body><div class="stage">
<div class="card">
<div class="photo" id="photo" aria-label="Photo, double tap to like"></div>
<div class="bar"><button class="like" id="like" aria-pressed="false" aria-label="Like"><svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true"><path d="M12 21s-7-4.6-9.5-9C.9 8.5 3 5 6.5 5c2 0 3.6 1.1 5.5 3 1.9-1.9 3.5-3 5.5-3C21 5 23.100 8.500 21.500 12 19 16.400 12 21 12 21z"/></svg></button><span id="cnt" aria-live="polite">128 likes</span></div>
</div>
</div>
<script>
const photo=document.getElementById('photo'),like=document.getElementById('like'),cnt=document.getElementById('cnt');
let liked=false,n=128;
function set(v){liked=v;n+=v?1:-1;like.setAttribute('aria-pressed',String(v));cnt.textContent=n+' likes';like.classList.remove('pulse');void like.offsetWidth;like.classList.add('pulse');}
like.addEventListener('click',()=>set(!liked));
let last=0,lx=0,ly=0;
photo.addEventListener('pointerup',e=>{const now=performance.now();
if(now-last<300&&Math.hypot(e.clientX-lx,e.clientY-ly)<30){last=0;const r=photo.getBoundingClientRect(),h=document.createElement('div');h.className='pop';h.style.left=(e.clientX-r.left)+'px';h.style.top=(e.clientY-r.top)+'px';h.innerHTML='<svg viewBox="0 0 24 24"><path d="M12 21s-7-4.600-9.500-9C.900 8.500 3 5 6.500 5c2 0 3.600 1.100 5.500 3 1.900-1.900 3.500-3 5.500-3C21 5 23.100 8.500 21.500 12 19 16.400 12 21 12 21z"/></svg>';photo.append(h);setTimeout(()=>h.remove(),720);if(!liked)set(true);}
else{last=now;lx=e.clientX;ly=e.clientY;}});
</script>
</body></html>