Ripple Effect
A circular wave that expands from the exact point of contact.
AI prompt
Implement a ripple effect on a 280x72px card-like button with overflow hidden and a 16px radius. On pointerdown, create a span positioned at the pointer's coordinates relative to the button; size it to a circle whose radius is the distance to the farthest corner, start at scale(0) with opacity 0.35, and animate to scale(1) and opacity 0 over 550ms with cubic-bezier(0.2,0.7,0.2,1); remove the span on animationend. For keyboard activation (keydown Enter or Space) start the ripple from the centre. Multiple ripples may overlap. The ripple must not intercept pointer events. Under prefers-reduced-motion replace it with a 120ms background flash.About this pattern
Definition
A translucent circle that starts at the pointer's position inside a button, grows to cover the whole surface and fades out. It confirms where and when the touch landed.
Purpose & UX principles
- Gives immediate confirmation of a press on large or ambiguous surfaces such as list rows and cards.
- It is feedback, not decoration: it must start on press, not on release.
- Clip the effect to the element's shape and never let it block the click.
Interaction states
- Idle, pressed (ripple starts), released (ripple finishes fading).
- Multiple quick presses create multiple overlapping ripples that clean themselves up.
Motion specification
- Expansion: scale from 0 to cover in 550ms, cubic-bezier(0.2, 0.7, 0.2, 1).
- Opacity: from 0.35 to 0 over the same duration.
- Ripple radius equals the distance to the farthest corner so it always fills the surface.
- Reduced motion: replaced by a brief 120ms flash of the background.
Responsive behaviour
- Works with mouse, touch and pen via pointer events.
- Keyboard activation (Enter or Space) starts the ripple from the centre.
Code
<button class="rip" id="rip">Tap anywhere on this button</button>: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}
.rip{position:relative;overflow:hidden;width:280px;max-width:100%;height:72px;border-radius:16px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer;-webkit-tap-highlight-color:transparent}
.rip:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.wave{position:absolute;border-radius:50%;background:var(--accent);opacity:.35;pointer-events:none;transform:scale(0);animation:wave .55s cubic-bezier(.2,.7,.2,1) forwards}
@keyframes wave{to{transform:scale(1);opacity:0}}
@media (prefers-reduced-motion:reduce){.wave{animation:flash .12s forwards;transform:scale(1);border-radius:0;inset:0!important;width:auto!important;height:auto!important}
@keyframes flash{from{opacity:.25}to{opacity:0}}}const btn=document.getElementById('rip');
function ripple(x,y){
const r=btn.getBoundingClientRect(),d=Math.max(Math.hypot(x,y),Math.hypot(r.width-x,y),Math.hypot(x,r.height-y),Math.hypot(r.width-x,r.height-y)),s=document.createElement('span');
s.className='wave';s.style.width=s.style.height=d*2+'px';s.style.left=x-d+'px';s.style.top=y-d+'px';
s.addEventListener('animationend',()=>s.remove());btn.append(s);
}
btn.addEventListener('pointerdown',e=>{const r=btn.getBoundingClientRect();ripple(e.clientX-r.left,e.clientY-r.top);});
btn.addEventListener('keydown',e=>{if((e.key==='Enter'||e.key===' ')&&!e.repeat)ripple(btn.offsetWidth/2,btn.offsetHeight/2);});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>Ripple Effect — 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}}
.rip{position:relative;overflow:hidden;width:280px;max-width:100%;height:72px;border-radius:16px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);font:inherit;font-weight:600;cursor:pointer;-webkit-tap-highlight-color:transparent}
.rip:focus-visible{outline:2px solid var(--accent);outline-offset:3px}
.wave{position:absolute;border-radius:50%;background:var(--accent);opacity:.35;pointer-events:none;transform:scale(0);animation:wave .55s cubic-bezier(.2,.7,.2,1) forwards}
@keyframes wave{to{transform:scale(1);opacity:0}}
@media (prefers-reduced-motion:reduce){.wave{animation:flash .12s forwards;transform:scale(1);border-radius:0;inset:0!important;width:auto!important;height:auto!important}
@keyframes flash{from{opacity:.25}to{opacity:0}}}
</style></head>
<body><div class="stage">
<button class="rip" id="rip">Tap anywhere on this button</button>
</div>
<script>
const btn=document.getElementById('rip');
function ripple(x,y){
const r=btn.getBoundingClientRect(),d=Math.max(Math.hypot(x,y),Math.hypot(r.width-x,y),Math.hypot(x,r.height-y),Math.hypot(r.width-x,r.height-y)),s=document.createElement('span');
s.className='wave';s.style.width=s.style.height=d*2+'px';s.style.left=x-d+'px';s.style.top=y-d+'px';
s.addEventListener('animationend',()=>s.remove());btn.append(s);
}
btn.addEventListener('pointerdown',e=>{const r=btn.getBoundingClientRect();ripple(e.clientX-r.left,e.clientY-r.top);});
btn.addEventListener('keydown',e=>{if((e.key==='Enter'||e.key===' ')&&!e.repeat)ripple(btn.offsetWidth/2,btn.offsetHeight/2);});
</script>
</body></html>