Cómo funciona
A track is laid over the container: its padding equals the border width and a mask removes the content box, leaving a faint ring. The beam is 12 dots, each moving at constant speed along offset-path: rect(), so length stays constant and the beam bends around corners. A second, blurred copy of the dots runs the same path in a layer masked to the outside of the border, so the head casts a halo on the surface around the container without ever covering its content. Browsers without rect() fall back to a rotating conic gradient.
Úsalo para
- The input of an AI assistant or chat entry, to say “ready, start typing”.
- The recommended plan on a pricing page.
- The entry card of a new feature, to draw attention for a short time.
Busca otra opción cuando
- Several beams on one screen: attention is split, so use at most one.
- Form errors and warnings: the beam is decorative and cannot express severity; use colour and text.
- Workspaces people stay on for long: constant motion tires the eye; start it only on focus or hover.
Uso
import { BorderBeam } from './BorderBeam.jsx'
export function PlanCard() {
return (
<BorderBeam radius={16} duration={6} colorFrom="#f97316" colorTo="#ec4899" style={{ padding: 20, background: '#fff' }}>
<h3>Yearly plan</h3>
<p>$198 / year · 4 free upgrades a month</p>
</BorderBeam>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
duration | number | 6 | Seconds per lap. |
beamSize | number | 90 | Beam length in px, measured along the border, whatever the container shape. |
colorFrom | string | '#6366f1' | Colour of the beam head. |
colorTo | string | '#a855f7' | Colour of the beam tail, which then fades to transparent. |
borderWidth | number | 1.5 | Border width in px. The container's inner padding must be larger. |
radius | number | 16 | Corner radius in px, shared by the container and the beam track. |
reverse | boolean | false | Circles counter-clockwise. |
delay | number | 0 | Animation delay in seconds. With several beams on screen, use negative values to stagger the start. |
glow | boolean | true | Adds a soft halo outside the border that follows the beam head. It is masked to the outside of the container, so it never covers the content. |
children | ReactNode | — | Container content. The container sets no background or shadow; use style or className. |
...rest | HTMLAttributes<HTMLDivElement> | — | Other attributes go to the root <div>. |
Accesibilidad
- The track, beam and glow are aria-hidden decoration with pointer-events: none, so clicks and screen readers are unaffected.
- With reduced motion the beam and glow stop and a static gradient outline is shown, which still marks the element as emphasised.
- No information depends on the animation.
Movimiento
One lap takes 6s by default at constant speed (linear, as a loop must). There is no enter or exit animation.
Añádelo a tu proyecto
Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.
BorderBeam.jsxborder-beam.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.







