Skip to content

Animated Beam for React

AnimatedBeam is a React effect that sends a light along an SVG path between two elements, measured from refs. Use it for integration diagrams and data-flow maps; it moves by transform only and rests off-screen.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/animated-beam.json
Billing
Chat
Docs
Your app

Waiting for sources

Integration diagram

Three sources feed one hub. Each beam is staggered with delay and bent with curvature, so the network reads as alive without any one beam competing. The beam is decorative (aria-hidden), so say what is connected in the labels.

Billing
Chat
Docs
Your app

Files to copy

5 folders · 6 files · 4 packages
From theme/src/
  • components/animated-beam/
  • hooks/{use-media-query.ts, use-preferences.ts}
  • motion/{beat-animations.ts, beat.ts, gate.ts}
  • lib/cn.ts
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/animated-beam.jsonRegistry item: animated-beam. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/glass-card/
  • components/switch/
  • hooks/{use-direction.ts, use-latest.ts}
  • motion/{light-follower.ts, tokens.ts}
  • lib/{field-control-shell.tsx, form.ts, heading.ts, motion-props.ts, state-light.tsx}
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/glass-card.json https://lokendra-builds.github.io/sheenui/r/switch.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

One connection, your colours

colorFrom and colorTo take any CSS colour (the defaults are the accent tokens), length and thickness shape the comet, and reverse sends it the other way, for a reply travelling back.

API
Client

Props

PropTypeDefaultDescription
containerRef (required)RefObject<HTMLElement | null>NoneThe positioned element that holds both ends (the beam fills it). Pass the same ref you put on that element.
fromRef (required)RefObject<HTMLElement | null>NoneElement the beam leaves from. Must be inside containerRef's element.
toRef (required)RefObject<HTMLElement | null>NoneElement the beam arrives at. Must be inside containerRef's element.
curvaturenumber0Bend of the path in px, measured sideways from the straight line between the two elements. Positive bends to the left of the direction of travel; 0 draws a straight line.
reversebooleanfalseRun from toRef to fromRef instead.
durationnumber2.4Seconds one pass of the beam takes from one end to the other.
intervalnumber1.2Seconds the path rests, empty, between two passes.
delaynumber0Seconds before the first pass (lets several beams in one diagram run out of step).
lengthnumber96Length of the travelling light in px, measured along the path.
thicknessnumber2.5Thickness of the light and of the track in px.
gapnumber6Gap in px kept between the path and the edge of each element.
colorFromstring"var(--sheen-accent)"Colour at the tail of the light, any CSS colour.
colorTostring"var(--sheen-accent-2)"Colour at the bright head of the light, any CSS colour.
trackbooleantrueDraw the faint static track under the light, so the connection reads even between passes.
fromOffsetBeamOffsetNoneNudges where the beam leaves fromRef, in px from its centre.
toOffsetBeamOffsetNoneNudges where the beam arrives at toRef, in px from its centre.
pausedbooleanfalseHold the light where it is (it carries on from there when unpaused).
classNamestringNoneAdds extra classes to the overlay.
styleCSSPropertiesNoneApplies an inline style to the overlay.

Keyboard

KeysAction
TabNot focusable: the beam never takes focus or pointer events, so the elements it connects stay usable.

Accessibility

  • Decorative: the overlay is aria-hidden. The connection must also be in text (a label, a heading or a sentence), because the picture is invisible to assistive technology.
  • paused holds the light where it is, so a page can offer a stop control (WCAG 2.2.2). It also rests off-screen and in hidden tabs.
  • Under reduced motion there is no light, only the faint still track between the elements.
  • The light is one element moved by transform and faded by opacity along positions sampled from the real path; nothing blurs, masks or filters the glass nodes.

When to use the animated beam effect

  • Use it in an integration diagram: a source card, your product in the middle and a destination, with a light running along the connection to show data flowing.
  • Use it in a "connected to" section or an architecture map, with several beams staggered by delay so the network feels alive without any of them competing.
  • Bend a path with curvature to route around a centre node, or reverse it for a response going back; the beam leaves from the edge of each element, not its centre.
  • Skip it when the relationship is the point of the content and nothing else says so; the beam is aria-hidden, so name the connection in text as well.
  • Pair it with GlassCard nodes, Badge labels on the nodes, and a Switch wired to the paused prop for a stop control.

Frequently asked questions

19 effects pages in all: browse them on All effects.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .