Back to Component Explorer
Ripple Button
buttonsInteractive button with expanding radial click ripple effect animation.
#button#ripple#animation#click
Live Interactive Preview
Component Source Code
Select language in the dropdownRippleButton.tsx
1'use client';23import React, { useState } from 'react';45export default function RippleButton() {6 const [ripples, setRipples] = useState<{ x: number; y: number; id: number }[]>([]);78 const addRipple = (e: React.MouseEvent<HTMLButtonElement>) => {9 const rect = e.currentTarget.getBoundingClientRect();10 const x = e.clientX - rect.left;11 const y = e.clientY - rect.top;12 const newRipple = { x, y, id: Date.now() };13 setRipples((prev) => [...prev, newRipple]);14 setTimeout(() => {15 setRipples((prev) => prev.filter((r) => r.id !== newRipple.id));16 }, 600);17 };1819 return (20 <button21 onClick={addRipple}22 className="relative overflow-hidden rounded-xl bg-violet-600 hover:bg-violet-700 px-6 sm:px-7 py-2.5 sm:py-3 text-sm font-semibold text-white shadow-md transition-all active:scale-95"23 >24 <span className="relative z-10">Click Ripple</span>25 {ripples.map((ripple) => (26 <span27 key={ripple.id}28 style={{29 top: ripple.y,30 left: ripple.x,31 transform: 'translate(-50%, -50%) scale(0)'32 }}33 className="absolute h-24 w-24 rounded-full bg-white/40 animate-[ping_0.6s_ease-out_forwards] pointer-events-none"34 />35 ))}36 </button>37 );38}Installation & Integration Guide
Step 1: Tailwind CSS v4 Setup
Tailwind DocsIf you do not have Tailwind installed yet, run this installation command:
Terminal
npm install tailwindcss @tailwindcss/postcss postcss
Then add the Tailwind directive to your main stylesheet (globals.css):
@import "tailwindcss";
Step 2: Install Icon Dependencies
npm install lucide-react react-icons
Step 3: Add Component File
Create a new file in your project at src/components/buttons/RippleButton.tsx and paste the copied code from the source viewer above.
Step 4: Usage Example
ExamplePage.tsx
1import RippleButton from '@/components/buttons/RippleButton';23export default function ExamplePage() {4 return (5 <main className="p-8 flex items-center justify-center min-h-screen">6 <RippleButton />7 </main>8 );9}