Components

Moving Border

A React moving border: a soft beam that travels along the rounded edge of any element, at constant speed around straight sides and corners alike. Use the MovingBorder wrapper for cards and badges, or the ready-made MovingBorderButton built on the DuskUI Button. Made with Motion and Tailwind CSS.

  • Wrapper + button
  • Follows rounded corners
  • Pauses off-screen
  • No layout shift
  • prefers-reduced-motion

Installation

$ npx shadcn@latest add https://duskui.com/r/moving-border.json

MovingBorderButton builds on the DuskUI Button; the CLI installs it automatically. Installing by hand? Add components/ui/button.tsx from the Button page first.

Usage

book-demo.tsx
import { MovingBorder, MovingBorderButton } from "@/components/dusk/moving-border/moving-border"

export function BookDemo() {
  return (
    <>
      <MovingBorderButton size="lg">Book a demo</MovingBorderButton>
      <MovingBorder radius={20} contentClassName="p-6">
        Any content
      </MovingBorder>
    </>
  )
}

Examples

Card wrapper

Wrap any block in MovingBorder. The content wrapper paints its own background, so the beam only shows through the borderWidth gap. A bigger beamSize gives a longer streak.

Edge functions

Run code close to your users in 30 regions.

Color, speed & direction

color takes any CSS color, speed is the seconds per lap and reverse runs it counter-clockwise.

Counter-clockwise badge

API Reference

MovingBorder also accepts every <div> prop. MovingBorderButton accepts the same beam props plus every DuskUI Button prop (except asChild); its className goes to the button and containerClassName to the border wrapper. It defaults to a pill with radius 9999, speed 3 and beamSize 56.

PropTypeDefaultDescription
colorstringvar(--color-primary)Any CSS color for the travelling light.
speednumber6 (button: 5)Seconds for one lap around the border.
radiusnumber12 (button: 9999)Corner radius in px. Large values give a pill.
borderWidthnumber1Border width in px: how much of the light shows around the content.
beamSizenumber64 (button: 48)Diameter of the beam in px.
reversebooleanfalseRun the beam counter-clockwise.
contentClassNamestring—Classes for the inner content wrapper (padding, background).
containerClassNamestring—MovingBorderButton only: classes for the outer border wrapper.

Accessibility

  • The beam and track are aria-hidden and absolutely positioned, so they never reach screen readers or change the content's size.
  • MovingBorderButton renders a native <button>; because the wrapper clips the beam, it draws the focus-visible ring on the wrapper so keyboard focus stays clearly visible.
  • With prefers-reduced-motion the beam is hidden and the whole edge is lit steadily instead; the animation also pauses whenever the element is off-screen.
  • The beam is positioned with Motion values, so it never re-renders React and is cleaned up on unmount.