# Animated Beam

> Connect two elements with a curved line and send a pulse of light along it.

Source: https://www.honestui.com/docs/animated/animated-beam

```tsx
"use client";

import { Bot, Calendar, Database, FileText, Mail, MessageSquare, User } from "honestui/icons";
import { forwardRef, useRef, type ReactNode } from "react";

import { AnimatedBeam } from "@/registry/default/animated/animated-beam";
import { cn } from "@/lib/utils";

const Node = forwardRef<HTMLDivElement, { children: ReactNode; className?: string; label: string }>(
  function Node({ children, className, label }, ref) {
    return (
      <div
        ref={ref}
        role="img"
        aria-label={label}
        className={cn(
          "z-10 flex size-11 items-center justify-center rounded-full border border-border bg-card text-foreground shadow-sm [&_svg]:size-4.5",
          className,
        )}
      >
        {children}
      </div>
    );
  },
);

export function AnimatedBeamDemo() {
  const containerRef = useRef<HTMLDivElement>(null);
  const docsRef = useRef<HTMLDivElement>(null);
  const mailRef = useRef<HTMLDivElement>(null);
  const chatRef = useRef<HTMLDivElement>(null);
  const calendarRef = useRef<HTMLDivElement>(null);
  const dataRef = useRef<HTMLDivElement>(null);
  const hubRef = useRef<HTMLDivElement>(null);
  const userRef = useRef<HTMLDivElement>(null);

  return (
    <div ref={containerRef} className="relative flex h-72 w-full max-w-lg items-center justify-between px-6">
      <div className="flex flex-col gap-4">
        <Node ref={docsRef} label="Docs"><FileText /></Node>
        <Node ref={mailRef} label="Mail"><Mail /></Node>
        <Node ref={chatRef} label="Chat"><MessageSquare /></Node>
        <Node ref={calendarRef} label="Calendar"><Calendar /></Node>
        <Node ref={dataRef} label="Database"><Database /></Node>
      </div>
      <Node ref={hubRef} label="Assistant" className="size-14 [&_svg]:size-6"><Bot /></Node>
      <Node ref={userRef} label="You"><User /></Node>

      <AnimatedBeam containerRef={containerRef} fromRef={docsRef} toRef={hubRef} />
      <AnimatedBeam containerRef={containerRef} fromRef={mailRef} toRef={hubRef} delay={0.6} />
      <AnimatedBeam containerRef={containerRef} fromRef={chatRef} toRef={hubRef} delay={1.2} />
      <AnimatedBeam containerRef={containerRef} fromRef={calendarRef} toRef={hubRef} delay={1.8} />
      <AnimatedBeam containerRef={containerRef} fromRef={dataRef} toRef={hubRef} delay={2.4} />
      <AnimatedBeam containerRef={containerRef} fromRef={hubRef} toRef={userRef} duration={3} />
    </div>
  );
}

```

## Overview [#overview]

Animated Beam draws a curved path between two elements and sends a light pulse along it. Use it to explain how data moves through a system: sources feeding an assistant, services calling an API, or steps in a pipeline. The path is measured from the elements' boxes and recomputed whenever the container or either node resizes, so layouts can be responsive.

## Installation [#installation]

<CliBlock commands="[&#x22;animated-beam&#x22;]" />

## Usage [#usage]

```tsx
import { AnimatedBeam } from "@/components/animated/animated-beam"

const containerRef = useRef<HTMLDivElement>(null)
const fromRef = useRef<HTMLDivElement>(null)
const toRef = useRef<HTMLDivElement>(null)

<div ref={containerRef} className="relative flex justify-between">
  <div ref={fromRef} className="z-10">Source</div>
  <div ref={toRef} className="z-10">Destination</div>
  <AnimatedBeam containerRef={containerRef} fromRef={fromRef} toRef={toRef} />
</div>
```

The container must be positioned. Give the nodes `z-10` or a background so the beam passes behind them. Stagger several beams with `delay` so their pulses don't arrive together.

## Accessibility [#accessibility]

The beam is decorative and hidden from assistive technology, so the diagram's meaning must come from the nodes. Give each node an accessible name, and describe the flow in nearby text when it matters. When reduced motion is requested, the pulse is removed and the resting path stays.

## API Reference [#api-reference]


  ### `containerRef`



">
    Positioned element both nodes sit inside.

  ### `fromRef`



">
    Element the beam starts from.

  ### `toRef`



">
    Element the beam ends at.

  ### `curvature`

type: `number` · default: `0`

Lifts the middle of the curve by this many px. Negative pushes it down. The path always leaves and arrives level.

  ### `reverse`

type: `boolean` · default: `false`

Sends the pulse from the end back to the start.

  ### `duration`

type: `number` · default: `4`

Seconds for the pulse to travel the path.

  ### `delay`

type: `number` · default: `0`

Seconds before the first pulse.

  ### `pulseLength`

type: `number` · default: `0.25`

Length of the pulse and its fading tail, as a fraction of the path.

  ### `pathColor`

type: `string` · default: `&#x22;var(--muted-foreground)&#x22;`

Color of the resting path.

  ### `pathWidth`

type: `number` · default: `1.5`

Stroke width in px.

  ### `pathOpacity`

type: `number` · default: `0.2`

Opacity of the resting path.

  ### `gradientStartColor`

type: `string` · default: `&#x22;var(--foreground)&#x22;`

Color at the head of the pulse.

  ### `gradientStopColor`

type: `string`

Color the tail fades to.

  ### `startXOffset`

type: `number` · default: `0`

Horizontal offset of the start point in px. 

    `startYOffset`

    , 

    `endXOffset`

    , and 

    `endYOffset`

     work the same way.

  ### `className`

type: `string`

Classes for the SVG.
