🌈 Animated Gradient Button
Upgrade your call-to-action buttons with the Animated Gradient Button, a stylish React component featuring seamless, looping color transitions. Designed for modern UIs, this button cycles through vibrant gradient combinations, making elements like 'Submit,' 'Get Started,' and 'Sign Up' more interactive and visually engaging. With smooth hover effects and fluid animations, it enhances user experience while maintaining high performance.
Preview
Follow below steps 👇🏻
Install dependencies
1npm i framer-motion
Component
Create a file animated-gradient-button.tsx in your components folder and paste this code
1import React from 'react';2import { HTMLMotionProps, motion } from 'framer-motion';34type AnimatedGradientButtonProps = HTMLMotionProps<'button'> & {5children?: React.ReactNode;6className?: string;7};89const AnimatedGradientButton = ({ children, className, ...props }: AnimatedGradientButtonProps) => {10return (11<motion.button12{...props}13initial={{ scale: 1, boxShadow: '0px 0px 10px rgba(255, 255, 255, 0.6)' }}14whileHover={{15scale: 1.08,16boxShadow: '0px 0px 20px rgba(255, 255, 255, 0.6)'17}}18whileTap={{ scale: 0.95 }}19animate={{20background: [21'linear-gradient(135deg, #ff6b6b, #ff8e53, #ffcc00)',22'linear-gradient(135deg, #42a5f5, #478ed1, #7b1fa2)',23'linear-gradient(135deg, #00c9a7, #2ecc71, #ffeb3b)',24'linear-gradient(135deg, #ff4081, #ff80ab, #f48fb1)',25'linear-gradient(135deg, #8e44ad, #c0392b, #e74c3c)',26'linear-gradient(135deg, #ffcc00, #ff5733, #ff1744)',27'linear-gradient(135deg, #009688, #26c6da, #00e5ff)',28'linear-gradient(135deg, #e91e63, #9c27b0, #673ab7)',29'linear-gradient(135deg, #f57c00, #ffca28, #ffeb3b)',30'linear-gradient(135deg, #00bcd4, #03a9f4, #1de9b6)'31],32transition: { duration: 15, repeat: Infinity, repeatType: 'mirror' }33}}34className={`relative overflow-hidden rounded-lg border-none px-6 py-3 text-lg font-semibold text-white tracking-wide shadow-md transition-all duration-300 hover:bg-opacity-90 ${className}`}35>36<motion.div37className="absolute inset-0 rounded-lg"38animate={{39boxShadow: [40'0px 0px 10px rgba(255, 255, 255, 0.3)',41'0px 0px 20px rgba(255, 255, 255, 0.6)',42'0px 0px 10px rgba(255, 255, 255, 0.3)'43],44transition: { duration: 2, repeat: Infinity, repeatType: 'mirror' }45}}46/>47<motion.span48className="absolute inset-0"49animate={{50background: 'radial-gradient(circle, rgba(255,255,255,0.15) 20%, transparent 80%)',51opacity: [0.5, 1, 0.5],52transition: { duration: 2, repeat: Infinity, repeatType: 'mirror' }53}}54/>55<span className="relative z-10">{children}</span>56</motion.button>57);58};5960export default AnimatedGradientButton;
Usage
1<AnimatedGradientButton className="rounded-md text-lg">2Let's go!3</AnimatedGradientButton>
⭐️ Got a question or feedback?
Feel free to reach out!