Swarm

Particle Text Animation for React

Your word or logo, set in dots that come in from the edge of the box. They gather along the frame, bow inward on hairline trails and lock into a honeycomb, most of them solid and a few left as hollow rings. Raise `fill` and solid dots fly in onto the rings, like a progress bar in your mark's shape; give it a new word and the same dots reroute to it.

  • Text
  • Canvas
  • Hero

Uses clsx, tailwind-merge

Open in ChatGPTOpen in Claude
fill0.90
dotSize6.0px
gap1.5px
trailstrue
drifttrue
duration1.15s(replays the demo)
stagger0.90s(replays the demo)
trailLength0.60(replays the demo)
<Swarm />

replays the demo when you let go.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Swarm: Your word or logo, set in dots that come in from the edge of the box. They gather along the frame, bow inward on hairline trails and lock into a honeycomb, most of them solid and a few left as hollow rings. Raise `fill` and solid dots fly in onto the rings, like a progress bar in your mark's shape; give it a new word and the same dots reroute to it.
This demo, Product Tabs: Three product names on tabs; each one reroutes the same dots into the next word.

1. Install it:
   npx shadcn@latest add @keyframeui/swarm-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/swarm-demo.json instead.)
   It adds the demo, components/swarm-demo.tsx, and the component, components/ui/swarm.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <Swarm> on its own.

3. These props set its feel. Change them before you change the file:
   - fill (default 0.9): Share of the mark that's solid, from 0 to 1; the rest are hollow rings, in a fixed random order. Raise it and solid dots fly in from the edge onto the rings, lower it and they fly out and leave their rings: a progress bar in the shape of your mark. `1` for a solid mark.
   - dotSize (default 6): Diameter of a landed dot, in px. The lattice adjusts to the box: past about 4,200 dots it widens, dots included, so it stays smooth, and under about 900 it tightens (down to half this size) so a word in a phone-sized box still reads.
   - gap (default 1.5): Space between neighbouring dots, in px.
   - trails (default true): Draw each dot's path behind it as a hairline that reels in once it lands.
   - drift (default true): Once settled, keep a few late dots coming in from the corners on long trails, so the mark never sits dead still. Off under reduced motion.
   - duration (default 1.15): Seconds a dot takes to fly from the edge to its slot on the way in. Each one varies by a quarter either way.
   - stagger (default 0.9): Seconds between the first dot leaving the edge and the last, on the way in.
   - trailLength (default 0.6): How far a trail lags behind its dot, as a share of the flight, from 0 (no trail) to 1 (the whole path so far).

4. Don't change, in components/ui/swarm.tsx:
   - Every dot's position is a closed-form function of time (a cubic from where it starts to its slot), so landings are exact, a change mid-flight starts from where the dot is, and the loop stops once nothing moves.
   - Dots land on a hex lattice inside the mark and never overlap there. Settled dots are drawn once into an offscreen canvas and blitted; moving dots, rings and trails are one path each, painted with one color or one canvas-wide gradient, so a dot takes the color of the spot it's in.
   - A trail is the dot's own curve drawn from a point that lags behind it, so it reels in when the dot lands. Never a fading smear: the canvas is transparent over your background.
   - New dots come in from the box's edge, behind their slot as seen from the middle; dots that leave go back out the same way. Nothing appears out of thin air mid-box.
   - Under reduced motion nothing travels: the mark crossfades in place and drift is off.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/swarm.md

Installation

Add the component on its own with the CLI, or copy the file in by hand.

The CLI writes components/ui/swarm.tsx and installs clsx and tailwind-merge. It needs the @keyframeui registry in components.json; add it once per project.

npx shadcn@latest add @keyframeui/swarm

Examples

Finished sections built with Swarm. Each one installs whole, with the component included.

Preloader

A workspace loading: the brand mark starts as hollow rings and fills with solid dots as the load reports progress.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Swarm: Your word or logo, set in dots that come in from the edge of the box. They gather along the frame, bow inward on hairline trails and lock into a honeycomb, most of them solid and a few left as hollow rings. Raise `fill` and solid dots fly in onto the rings, like a progress bar in your mark's shape; give it a new word and the same dots reroute to it.
This demo, Preloader: A workspace loading: the brand mark starts as hollow rings and fills with solid dots as the load reports progress.

1. Install it:
   npx shadcn@latest add @keyframeui/swarm-loader-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/swarm-loader-demo.json instead.)
   It adds the demo, components/swarm-loader-demo.tsx, and the component, components/ui/swarm.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <Swarm> on its own.

3. These props set its feel. Change them before you change the file:
   - fill (default 0.9): Share of the mark that's solid, from 0 to 1; the rest are hollow rings, in a fixed random order. Raise it and solid dots fly in from the edge onto the rings, lower it and they fly out and leave their rings: a progress bar in the shape of your mark. `1` for a solid mark.
   - dotSize (default 6): Diameter of a landed dot, in px. The lattice adjusts to the box: past about 4,200 dots it widens, dots included, so it stays smooth, and under about 900 it tightens (down to half this size) so a word in a phone-sized box still reads.
   - gap (default 1.5): Space between neighbouring dots, in px.
   - trails (default true): Draw each dot's path behind it as a hairline that reels in once it lands.
   - drift (default true): Once settled, keep a few late dots coming in from the corners on long trails, so the mark never sits dead still. Off under reduced motion.
   - duration (default 1.15): Seconds a dot takes to fly from the edge to its slot on the way in. Each one varies by a quarter either way.
   - stagger (default 0.9): Seconds between the first dot leaving the edge and the last, on the way in.
   - trailLength (default 0.6): How far a trail lags behind its dot, as a share of the flight, from 0 (no trail) to 1 (the whole path so far).

4. Don't change, in components/ui/swarm.tsx:
   - Every dot's position is a closed-form function of time (a cubic from where it starts to its slot), so landings are exact, a change mid-flight starts from where the dot is, and the loop stops once nothing moves.
   - Dots land on a hex lattice inside the mark and never overlap there. Settled dots are drawn once into an offscreen canvas and blitted; moving dots, rings and trails are one path each, painted with one color or one canvas-wide gradient, so a dot takes the color of the spot it's in.
   - A trail is the dot's own curve drawn from a point that lags behind it, so it reels in when the dot lands. Never a fading smear: the canvas is transparent over your background.
   - New dots come in from the box's edge, behind their slot as seen from the middle; dots that leave go back out the same way. Nothing appears out of thin air mid-box.
   - Under reduced motion nothing travels: the mark crossfades in place and drift is off.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/swarm.md

404 Page

A not-found page whose number is two-thirds solid; the hollow rings are the part that never arrived, and late dots keep drifting in.

Take this demo to your coding agent.
Add this moment from KeyframeUI to our project and adapt it to our content.

Swarm: Your word or logo, set in dots that come in from the edge of the box. They gather along the frame, bow inward on hairline trails and lock into a honeycomb, most of them solid and a few left as hollow rings. Raise `fill` and solid dots fly in onto the rings, like a progress bar in your mark's shape; give it a new word and the same dots reroute to it.
This demo, 404 Page: A not-found page whose number is two-thirds solid; the hollow rings are the part that never arrived, and late dots keep drifting in.

1. Install it:
   npx shadcn@latest add @keyframeui/swarm-404-demo
   (If the CLI can't find @keyframeui, use https://keyframeui.com/r/swarm-404-demo.json instead.)
   It adds the demo, components/swarm-404-demo.tsx, and the component, components/ui/swarm.tsx.

2. Make it ours: our copy, data, images and colors. Keep the structure the motion depends on. If we only need the effect, use <Swarm> on its own.

3. These props set its feel. Change them before you change the file:
   - fill (default 0.9): Share of the mark that's solid, from 0 to 1; the rest are hollow rings, in a fixed random order. Raise it and solid dots fly in from the edge onto the rings, lower it and they fly out and leave their rings: a progress bar in the shape of your mark. `1` for a solid mark.
   - dotSize (default 6): Diameter of a landed dot, in px. The lattice adjusts to the box: past about 4,200 dots it widens, dots included, so it stays smooth, and under about 900 it tightens (down to half this size) so a word in a phone-sized box still reads.
   - gap (default 1.5): Space between neighbouring dots, in px.
   - trails (default true): Draw each dot's path behind it as a hairline that reels in once it lands.
   - drift (default true): Once settled, keep a few late dots coming in from the corners on long trails, so the mark never sits dead still. Off under reduced motion.
   - duration (default 1.15): Seconds a dot takes to fly from the edge to its slot on the way in. Each one varies by a quarter either way.
   - stagger (default 0.9): Seconds between the first dot leaving the edge and the last, on the way in.
   - trailLength (default 0.6): How far a trail lags behind its dot, as a share of the flight, from 0 (no trail) to 1 (the whole path so far).

4. Don't change, in components/ui/swarm.tsx:
   - Every dot's position is a closed-form function of time (a cubic from where it starts to its slot), so landings are exact, a change mid-flight starts from where the dot is, and the loop stops once nothing moves.
   - Dots land on a hex lattice inside the mark and never overlap there. Settled dots are drawn once into an offscreen canvas and blitted; moving dots, rings and trails are one path each, painted with one color or one canvas-wide gradient, so a dot takes the color of the spot it's in.
   - A trail is the dot's own curve drawn from a point that lags behind it, so it reels in when the dot lands. Never a fading smear: the canvas is transparent over your background.
   - New dots come in from the box's edge, behind their slot as seen from the middle; dots that leave go back out the same way. Nothing appears out of thin air mid-box.
   - Under reduced motion nothing travels: the mark crossfades in place and drift is off.
   Its timing is all in the TIMING block at the top of that file.

Docs: https://keyframeui.com/components/swarm.md

Props

text

Typestring

A word or short line for the dots to form. Use \n for a second line. Set in textFont at weight 800 and fitted inside the box.

textFont

TypestringDefault"ui-sans-serif, system-ui, sans-serif"

Font family text is set in before it's turned into dots. It's measured again once your web fonts load.

path

Typestring

An SVG path (d) for the dots to form, such as your logo mark, read against viewBox. Used when there's no text; with neither, the dots form a disc.

viewBox

TypestringDefault"0 0 24 24"

The coordinate box path is drawn in, like an SVG's viewBox.

fill

TypenumberDefault0.9

Share of the mark that's solid, from 0 to 1; the rest are hollow rings, in a fixed random order. Raise it and solid dots fly in from the edge onto the rings, lower it and they fly out and leave their rings: a progress bar in the shape of your mark. 1 for a solid mark.

dotSize

TypenumberDefault6

Diameter of a landed dot, in px. The lattice adjusts to the box: past about 4,200 dots it widens, dots included, so it stays smooth, and under about 900 it tightens (down to half this size) so a word in a phone-sized box still reads.

gap

TypenumberDefault1.5

Space between neighbouring dots, in px.

trails

TypebooleanDefaulttrue

Draw each dot's path behind it as a hairline that reels in once it lands.

drift

TypebooleanDefaulttrue

Once settled, keep a few late dots coming in from the corners on long trails, so the mark never sits dead still. Off under reduced motion.

duration

TypenumberDefault1.15

Seconds a dot takes to fly from the edge to its slot on the way in. Each one varies by a quarter either way.

stagger

TypenumberDefault0.9

Seconds between the first dot leaving the edge and the last, on the way in.

trailLength

TypenumberDefault0.6

How far a trail lags behind its dot, as a share of the flight, from 0 (no trail) to 1 (the whole path so far).

label

Typestring

Describes the mark for screen readers. Defaults to text; without either, the swarm is decorative and hidden from them.

dotClassName

TypestringDefault"text-[#2f45e8] dark:text-[#8b98ff]"

A text-* color for the dots, rings and trails. The canvas reads it, so dark: variants work.

gradientClassName

Typestring

A second text-* color. Dots, rings and trails blend from dotClassName at the top left to this at the bottom right, by where each one is, so a dot changes color as it crosses the box. One gradient for the whole canvas, so it costs nothing extra.

ringClassName

Typestring

A text-* color for the hollow rings alone, so what's still to come reads apart from what's solid, like a muted gray under a bright fill. Without it, rings take the dots' color.

canvasClassName

Typestring

Classes for the canvas. It fills the box by default and the mark is fitted inside it, so position it to set the mark in one part of the box.

onSettle

Type() => void

Called each time every dot has landed: after the entrance, a new mark or a new fill. Use it to reveal the page behind a preloader or move to the next word.

children

TypeReact.ReactNode

Content drawn over the dots.

className

Typestring

Classes for the box. Give it a size: the mark is fitted inside it, about 9% in from each edge.