Getting Started
Frameworks
Components
Buttons
Text Animations
Backgrounds
Device Mocks
Background Gradient
An animated gradient that sits at the background of a card, button or anything.
Usage
Code
import { motion } from "framer-motion";import { cnBase } from "tailwind-variants";export interface BackgroundGradientProps {children?: React.ReactNode;className?: string;containerClassName?: string;animate?: boolean;}export const BackgroundGradient: React.FC<BackgroundGradientProps> = ({children,className,containerClassName,animate = true,}) => {const variants = {initial: {backgroundPosition: "0 50%",},animate: {backgroundPosition: ["0, 50%", "100% 50%", "0 50%"],},};return (<div className={cnBase("relative p-[4px] group", containerClassName)}><motion.divvariants={animate ? variants : undefined}initial={animate ? "initial" : undefined}animate={animate ? "animate" : undefined}transition={animate? {duration: 5,repeat: Infinity,repeatType: "reverse",}: undefined}style={{backgroundSize: animate ? "400% 400%" : undefined,}}className={cnBase("absolute inset-0 rounded-3xl z-[1] opacity-60 group-hover:opacity-100 blur-xl transition duration-500 will-change-transform"," bg-[radial-gradient(circle_farthest-side_at_0_100%,#00ccb1,transparent),radial-gradient(circle_farthest-side_at_100%_0,#7b61ff,transparent),radial-gradient(circle_farthest-side_at_100%_100%,#ffc414,transparent),radial-gradient(circle_farthest-side_at_0_0,#1ca0fb,#141316)]")}/><motion.divvariants={animate ? variants : undefined}initial={animate ? "initial" : undefined}animate={animate ? "animate" : undefined}transition={animate? {duration: 5,repeat: Infinity,repeatType: "reverse",}: undefined}style={{backgroundSize: animate ? "400% 400%" : undefined,}}className={cnBase("absolute inset-0 rounded-3xl z-[1] will-change-transform","bg-[radial-gradient(circle_farthest-side_at_0_100%,#00ccb1,transparent),radial-gradient(circle_farthest-side_at_100%_0,#7b61ff,transparent),radial-gradient(circle_farthest-side_at_100%_100%,#ffc414,transparent),radial-gradient(circle_farthest-side_at_0_0,#1ca0fb,#141316)]")}/><div className={cnBase("relative z-10", className)}>{children}</div></div>);};
Props
Attribute | Type | Description | Default |
---|---|---|---|
children | React.ReactNode | The content to be rendered within the gradient background. | undefined |
className | string | The CSS class to be applied to the inner div. | undefined |
containerClassName | string | The CSS class to be applied to the outermost div. | undefined |
animate | string | Color of the avatars | true |
On this page