# Border Beam

> A small light that travels around any element's border at a steady pace. Subtle, premium, never distracting.

Category: Cards · Free · Updated 2026-10-20 · Live demo: https://www.motionkitui.com/components/border-beam

## When to use it

Featured cards, announcement banners and "new" badges. It adds a premium touch to any element without changing its layout.

## How it works

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.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/border-beam.json
```

Or copy `components/motionkit/border-beam.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| 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. |

## Accessibility

- **Keyboard: Not applicable.** Decoration only. It adds nothing to focus and never takes clicks.
- **Screen readers: Pass.** The beam is hidden from assistive tech.
- **Reduced motion: Partial.** 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.
- **Colour contrast: Not applicable.** Decorative only. It never sits behind text.

## Source

```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>
  );
}
```
