Copies›Glow Border Button

Glow Border Button

A button whose border carries a travelling beam of light (border beam); Copia adds a blurred halo that bleeds outside the edge and a beam that smoothly speeds up on hover or keyboard focus without restarting its lap.

Copy a ready prompt for Claude Code, Codex or Cursor

Seen on

Magic UI (Border Beam)

Dependencies

reacttailwindcssmotionlucide-react

Interaction type

buttons

Install via CLI

pnpm dlx shadcn@latest add @copia/glow-border-button

Without the namespace: npx shadcn@latest add https://copia-ui.vercel.app/r/glow-border-button.json

How to use

demo.tsx
import { ArrowRight } from "lucide-react"
import { GlowBorderButton, type GlowBorderButtonProps } from "./glow-border-button"

export default function Demo(props: Pick<GlowBorderButtonProps, "size" | "duration" | "hoverSpeed" | "borderWidth" | "glow" | "reverse" | "colorFrom" | "colorTo">) {
  return (
    <div className="grid flex-1 place-items-center p-6">
      <GlowBorderButton size={70} glow={12} {...props} className="scale-[1.8] px-8 py-4 text-base">
        Get started <ArrowRight className="size-4" />
      </GlowBorderButton>
    </div>
  )
}

Customization

Use the sliders button at the top right of the preview to tweak size, duration, hoverSpeed, borderWidth, glow, reverse, colorFrom, colorTo live and copy the generated JSX.

Props

PropTypeDefaultDescription
sizenumber60Length of the beam in px.
durationnumber4Seconds for one lap at rest.
hoverSpeednumber3Lap speed multiplier while hovered or focused; eases in and out.
colorFromstring"#ffaa40"Leading color of the beam.
colorTostring"#9c40ff"Trailing color of the beam.
borderWidthnumber1.5Border thickness in px.
glownumber14Blur radius of the outer halo in px; 0 turns it off.
reversebooleanfalseRun the beam counter-clockwise.

Attribution

Inspired by Magic UI (Border Beam). Recreated by Copia.

Read how it was reverse engineered

Source code

glow-border-button.tsx
"use client"

import { useRef, useState } from "react"
import { motion, useAnimationFrame, useMotionTemplate, useMotionValue, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"

export type GlowBorderButtonProps = Omit<React.ComponentProps<"button">, "color"> & {
  /** Length of the beam in px (it is a square travelling along the edge). */
  size?: number
  /** Seconds for one lap at rest. */
  duration?: number
  /** Lap speed multiplier while hovered or focused (1 = no change). */
  hoverSpeed?: number
  /** Leading color of the beam. */
  colorFrom?: string
  /** Trailing color of the beam. */
  colorTo?: string
  /** Border thickness in px. */
  borderWidth?: number
  /** Blur radius in px of the halo that bleeds outside the border (0 = off). */
  glow?: number
  /** Run the beam counter-clockwise. */
  reverse?: boolean
}

/** A button whose border carries a beam of light that travels around it. */
export function GlowBorderButton({
  size = 60,
  duration = 4,
  hoverSpeed = 3,
  colorFrom = "#ffaa40",
  colorTo = "#9c40ff",
  borderWidth = 1.5,
  glow = 14,
  reverse = false,
  className,
  children,
  onPointerEnter,
  onPointerLeave,
  onFocus,
  onBlur,
  ...props
}: GlowBorderButtonProps) {
  const reduceMotion = useReducedMotion()
  const [boost, setBoost] = useState(false)
  const progress = useMotionValue(12)
  const speed = useRef(1)

  // Drive offset-distance by hand so the speed can ease up and down mid-lap
  // (changing a Motion `duration` would restart the loop and jump the beam).
  useAnimationFrame((_, delta) => {
    if (reduceMotion) return
    const target = boost ? hoverSpeed : 1
    speed.current += (target - speed.current) * Math.min(1, delta / 180)
    const step = (delta / 1000 / duration) * 100 * speed.current
    const next = (progress.get() + (reverse ? -step : step) + 100) % 100
    progress.set(next)
  })

  const offsetDistance = useMotionTemplate`${progress}%`
  const beamStyle = {
    width: size,
    offsetPath: `rect(0 auto auto 0 round ${size}px)`,
    offsetDistance,
    background: `linear-gradient(to left, ${colorFrom}, ${colorTo}, transparent)`,
  }

  return (
    <button
      type="button"
      onPointerEnter={(e) => (setBoost(true), onPointerEnter?.(e))}
      onPointerLeave={(e) => (setBoost(false), onPointerLeave?.(e))}
      onFocus={(e) => (setBoost(true), onFocus?.(e))}
      onBlur={(e) => (setBoost(false), onBlur?.(e))}
      className={cn(
        "group relative isolate inline-flex items-center justify-center gap-2 rounded-full px-6 py-3 text-sm font-medium",
        "bg-background text-foreground outline-none transition-transform active:scale-[0.98]",
        "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
        className,
      )}
      {...props}
    >
      {/* Halo: the same beam, blurred, behind the button so it bleeds outside the edge. */}
      {glow > 0 && !reduceMotion && (
        <span aria-hidden className="pointer-events-none absolute inset-0 -z-10 rounded-[inherit]">
          <motion.span
            className="absolute aspect-square opacity-45"
            style={{ ...beamStyle, filter: `blur(${glow}px)` }}
          />
        </span>
      )}
      {/* Opaque face (with a resting border) so the halo only shows outside the edge. */}
      <span
        aria-hidden
        className="pointer-events-none absolute inset-0 -z-[5] rounded-[inherit] bg-background"
        style={{ boxShadow: `inset 0 0 0 ${borderWidth}px var(--border)` }}
      />
      {/* Beam: masked to the border ring only (padding-box minus border-box). */}
      <span
        aria-hidden
        className="pointer-events-none absolute inset-0 rounded-[inherit] border-transparent"
        style={{
          borderWidth,
          borderStyle: "solid",
          mask: "linear-gradient(transparent, transparent) padding-box, linear-gradient(#000, #000) border-box",
          maskComposite: "intersect",
        }}
      >
        {reduceMotion ? (
          <span
            className="absolute inset-0 rounded-[inherit]"
            style={{ background: `linear-gradient(90deg, ${colorTo}, ${colorFrom})`, opacity: 0.8 }}
          />
        ) : (
          <motion.span className="absolute aspect-square" style={beamStyle} />
        )}
      </span>
      <span className="relative inline-flex items-center gap-2">{children}</span>
    </button>
  )
}

Keep in mind

Most components here are recreations of the best interfaces out there. We don't claim to be the original creators: this is our attempt to reverse engineer, replicate and often add a few features. We credit everyone we can; if we missed someone, let us know.

Contact

Found a bug or a missing credit? Open an issue

License & usage

  • — Free to use and modify in personal and commercial projects (MIT).
  • — No attribution required, but a link back to Copia is appreciated.
  • — Demo images are not part of the license; replace them with your own.
PreviousDynamic IslandNext Perspective Carousel