Pulsating Button
An animated pulsating button useful for capturing attention of users.
Installation
Copy and paste the following code into your project.
"use client"
import React from "react"
import { cn } from "@/lib/utils"
interface PulsatingButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
pulseColor?: string
duration?: string
}
export function PulsatingButton({
className,
children,
pulseColor = "#0096ff",
duration = "1.5s",
...props
}: PulsatingButtonProps) {
return (
<button
className={cn(
"relative text-center cursor-pointer flex justify-center items-center rounded-lg text-white dark:text-black bg-blue-500 dark:bg-blue-500 px-4 py-2",
className
)}
style={
{
"--pulse-color": pulseColor,
"--duration": duration,
} as React.CSSProperties
}
{...props}
>
<div className="relative z-10">{children}</div>
<div className="absolute top-1/2 left-1/2 size-full rounded-lg bg-inherit animate-pulse -translate-x-1/2 -translate-y-1/2" />
</button>
)
}
Update the import paths to match your project setup.
Update tailwind.config.js
Add the following animations to your tailwind.config.js
file:
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
theme: {
extend: {
animation: {
pulse: "pulse var(--duration) ease-out infinite",
},
keyframes: {
pulse: {
"0%, 100%": { boxShadow: "0 0 0 0 var(--pulse-color)" },
"50%": { boxShadow: "0 0 0 8px var(--pulse-color)" },
},
},
},
},
}
Props
Prop | Type | Description |
---|---|---|
children | React.ReactNode | The content of the button. |
className | string | Additional class names for the button. |
pulseColor | string | The rbg numbers only for the color of the pulsing waves. |
duration | string | The time span of one pulse. |