Border Beam

A beam that travels around the border of a card while something is in progress. Its head is the primary colour and its tail fades out behind it, following the rounded corners exactly.

Border Trail moves a soft neutral spot along the edge and fits a loading placeholder. Border Beam draws a line on the border itself, in the brand colour, and fades away when the work it stands for stops.

Examples

While a task runs

The beam runs while the sync runs. Pause it and the beam fades out, then stops.

Design library

Syncing 1,204 files from the shared drive

Two beams

Two shorter beams on opposite sides, travelling anticlockwise.

Drafting a reply

Installation

npx shadcn@latest add https://ui.ndekocode.dev/r/motion-border-beam.json

Component API

BorderBeam

Place it inside a card with position: relative. It reads the card's corner radius and size, and redraws when they change. The card does not need overflow: hidden.

PropTypeDefaultDescription
durationnumber6Seconds for a beam to go once around the card.
lengthnumber0.3The length of a beam, as a share of the border, from 0 to 1.
widthnumber1.5The thickness of the beam, in px.
countnumber1How many beams travel, evenly spaced.
offsetnumber0Where the beam starts, as a share of the border from the top left corner.
reversebooleanfalseWhether the beam travels anticlockwise.
activebooleantrueWhether the beam shows. Turning it off fades the beam out, then pauses it.
radiusnumberThe corner radius in px, when it should not be read from the card.
classNamestringClasses for the SVG. The colour comes from text-primary and can be replaced.

Accessibility and motion

  • The beam is decorative SVG and hidden from assistive technology. Say what is in progress in text, as the sync example does with a polite live region.
  • The beam pauses while the card is off screen.
  • With reduced motion the beam stays still where it starts.

Credits

Inspired by the border beam of Magic UI, redrawn as a dashed SVG stroke on our tokens.