A container whose border carries a light that travels around it.
A small light that travels around any element's border at a steady pace. Subtle, premium, never distracting.
Featured
Studio plan
A light travels the border.
Customize
Usage
import { BorderBeam } from "@/components/motionkit/border-beam";
{/* any element with position: relative and a matching radius */}
<div className="relative rounded-2xl border p-6">
<h3>Studio plan</h3>
<BorderBeam />
</div>Motion
The exact curves this component runs, plotted with Motion's own maths.
Lap
Runs on its own
Featured cards, announcement banners and "new" badges. It adds a premium touch to any element without changing its layout.
A short gradient bar rides along a CSS offset-path shaped as the element's rounded rectangle, and Motion animates offset-distance from 0% to 100%, so the speed stays even round corners and straight edges alike. A mask-composite cut-out hides everything except a border-width ring, so the beam never crosses your content. With reduced motion on, it isn't rendered at all.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/border-beam.jsonnpm install motionSave as components/motionkit/border-beam.tsx.
"use client";
import { motion, useReducedMotion } from "motion/react";
type BorderBeamProps = {
/** Length of the beam in pixels. */
size?: number;
/** Seconds for one lap of the border. */
duration?: number;
/** Seconds to wait before the first lap. Offset several beams to stagger them. */
delay?: number;
/** Colour at the head of the beam. */
colorFrom?: string;
/** Colour the tail fades through. */
colorTo?: string;
/** Border thickness in pixels. */
borderWidth?: number;
/** Corner radius of the element it sits in, so the beam follows the curve. */
radius?: number;
/** Travel anticlockwise. */
reverse?: boolean;
};
/**
* A small light that travels around the border of whatever it sits in.
* Place it as the last child of any element with position: relative.
*/
export function BorderBeam({
size = 80,
duration = 6,
delay = 0,
colorFrom = "#5FAEB4",
colorTo = "#A56D5B",
borderWidth = 1.5,
radius = 16,
reverse = false,
}: BorderBeamProps) {
const reduceMotion = useReducedMotion();
if (reduceMotion) return null;
return (
<div
aria-hidden
className="pointer-events-none absolute inset-0"
style={{
borderRadius: radius,
// cut the middle out, so the beam only ever shows on the border
padding: borderWidth,
WebkitMask: "linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)",
WebkitMaskComposite: "xor",
maskComposite: "exclude",
}}
>
{/* the beam rides a rounded-rectangle path, so it keeps a steady speed on any shape */}
<motion.div
className="absolute aspect-square"
style={{
width: size,
offsetPath: `rect(0 auto auto 0 round ${radius}px)`,
// the head leads in the direction of travel, with the tail fading out behind it
background: `linear-gradient(to ${reverse ? "right" : "left"}, ${colorFrom}, ${colorTo}, transparent)`,
}}
initial={{ offsetDistance: reverse ? "100%" : "0%" }}
animate={{ offsetDistance: reverse ? ["100%", "0%"] : ["0%", "100%"] }}
transition={{ duration, delay, repeat: Infinity, ease: "linear" }}
/>
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| size | number | 80 | Length of the beam in pixels. |
| duration | number | 6 | Seconds for one lap of the border. |
| delay | number | 0 | Seconds before the first lap. Offset several beams to stagger them. |
| colorFrom / colorTo | string | "#5FAEB4" / "#A56D5B" | Colour at the head of the beam, and the colour its tail fades through. |
| borderWidth | number | 1.5 | Border thickness in pixels. |
| radius | number | 16 | Corner radius of the parent, so the beam follows the curve. |
| reverse | boolean | false | Travel anticlockwise. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/border-beam.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
The beam is removed for reduced-motion users. It loops forever otherwise, so if it sits beside other content for more than 5 seconds, WCAG 2.2.2 asks you to add a pause control.
A container whose border carries a light that travels around it.
A card with a soft glow that tracks the pointer across its surface.
One soft beam follows the pointer across a grid, lighting the borders and faces of the cards it passes.