Command Palette

Search for a command to run...

Hover Border Gradient

A beautiful hover border gradient effect for buttons and containers.

Hover Border Gradient

A beautiful hover border gradient effect that animates when you hover over the component.

Installation

Copy the code

components/hover-border-gradient.tsx
"use client";
import React, { useState } from "react";
import { motion, AnimatePresence } from "framer-motion";
import { cn } from "@/lib/utils";

export const HoverBorderGradient = ({
children,
containerClassName,
className,
as: Tag = "button",
duration = 1,
clockwise = true,
...props
}: {
children: React.ReactNode;
containerClassName?: string;
className?: string;
as?: React.ElementType;
duration?: number;
clockwise?: boolean;
} & React.HTMLAttributes) => {
const [hovered, setHovered] = useState(false);

const movingBackground = (
  
    
); return ( setHovered(true)} onMouseLeave={() => setHovered(false)} className={cn( "relative flex h-min w-fit flex-col flex-nowrap items-center justify-center overflow-visible rounded-full border border-border/40 bg-background/50 p-px decoration-clone transition-all duration-500 hover:bg-transparent", containerClassName )} {...props} >
{children}
{hovered && movingBackground}
); };

Props

PropTypeDefaultDescription
children*ReactNode-The content inside the gradient container.
containerClassNamestring-Custom classes for the outer container.
classNamestring-Custom classes for the inner container.
asElementTypebuttonThe HTML element to render as.
durationnumber1Animation duration.
clockwisebooleantrueDirection of the gradient rotation.