# BorderBeam

> A single comet of light riding a container's border: a white-hot head, a long feathered tail fading between two colours, a dim hairline that lights up only within the comet's reach, and a soft bloom that sits on the edge.

- Package: `fancy-ui-svelte` (Svelte 5 + Tailwind CSS v4)
- Category: Effects
- Tags: animation, border, gradient, beam, comet, glow
- Types: `BorderBeamProps`
- Docs: https://fancy-ui.rama.app/docs/components/border-beam
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/src/lib/fancy-ui/border-beam

## Import

```svelte
<script lang="ts">
  import { BorderBeam } from 'fancy-ui-svelte';
</script>
```

Setup (once per project): `npm install fancy-ui-svelte`, then add `@import "fancy-ui-svelte/tailwind.css";` after `@import "tailwindcss";` in your main CSS file. Full guide: https://fancy-ui.rama.app/llms.txt

React: `import { BorderBeam } from 'fancy-ui-react';` (`class` becomes `className`, snippets become `ReactNode`, DOM callbacks are camel-cased; exact names on https://fancy-ui.rama.app/docs/components/react/border-beam.md).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `size` | `number` | `200` | Diameter of the pool of light around the comet's head, in pixels |
| `duration` | `number` | `9` | Time for one full lap of the border, in seconds |
| `borderWidth` | `number` | `1.5` | Border width in pixels |
| `anchor` | `number` | `90` | Where the comet starts (and rests with reduced motion), as a percentage of the perimeter clockwise from the top-left (0-100) |
| `colorFrom` | `string` | `"#8ec5ff"` | Colour of the head and the start of the tail |
| `colorTo` | `string` | `"#c084fc"` | Colour the tail fades into |
| `delay` | `number` | `0` | Seconds behind the start position; the comet runs from the first frame |
| `tail` | `number` | `0.25` | Length of the tail as a share of the perimeter (0-1) |
| `glow` | `number` | `0.6` | Strength of the bloom, halo and inner spill of light (0-1) |
| `reverse` | `boolean` | `false` | Travel counter-clockwise instead of clockwise |

## Examples

### Basic Usage

A comet riding a nested-frame card.

```svelte
<script lang="ts">
	import { BorderBeam } from "fancy-ui-svelte";
</script>

<!-- outer frame -->
<div
	class="relative mx-auto w-full max-w-md overflow-hidden rounded-2xl border border-black/[0.08] bg-[#f4f4f5] p-1.5 [--border-beam-radius:16px] dark:border-white/[0.08] dark:bg-[#0b0b0c]"
>
	<!-- inner frame -->
	<div
		class="relative rounded-[11px] border border-black/[0.06] bg-[#fafafa] p-6 dark:border-white/[0.06] dark:bg-[#141416]"
	>
		<div class="flex items-center gap-3">
			<span
				class="flex size-9 items-center justify-center rounded-lg border border-black/[0.08] bg-white text-sm dark:border-white/[0.08] dark:bg-white/[0.03]"
				aria-hidden="true"
			>
				<svg viewBox="0 0 16 16" class="size-4 text-neutral-500 dark:text-neutral-400" fill="none">
					<path
						d="M8 1.5v3M8 11.5v3M1.5 8h3M11.5 8h3"
						stroke="currentColor"
						stroke-width="1.3"
						stroke-linecap="round"
					/>
					<circle cx="8" cy="8" r="1.6" fill="currentColor" />
				</svg>
			</span>
			<div>
				<p class="text-sm font-medium text-neutral-900 dark:text-neutral-100">Deploy in progress</p>
				<p class="text-xs text-neutral-500">edge-eu-west · build 1482</p>
			</div>
		</div>
		<div class="mt-5 h-1 overflow-hidden rounded-full bg-black/[0.05] dark:bg-white/[0.06]">
			<div class="h-full w-3/5 rounded-full bg-neutral-400/60 dark:bg-neutral-500/60"></div>
		</div>
		<p class="mt-3 font-mono text-[11px] text-neutral-500">Optimising assets — 3 of 5 steps</p>
	</div>
	<BorderBeam />
</div>
```

### Custom Colors

Two calm colours per comet: head and tail.

```svelte
<script lang="ts">
	import { BorderBeam } from "fancy-ui-svelte";

	const pairs = [
		{ label: "Ice → Lilac", from: "#8ec5ff", to: "#c084fc" },
		{ label: "Mint → Sea", from: "#a7f3d0", to: "#38bdf8" },
		{ label: "Ember → Rose", from: "#fcd9a8", to: "#f472b6" },
	];
</script>

<div class="flex flex-wrap justify-center gap-6">
	{#each pairs as pair (pair.label)}
		<div
			class="relative flex h-32 w-48 items-end overflow-hidden rounded-xl border border-black/[0.08] bg-[#fafafa] p-4 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
		>
			<p class="font-mono text-[11px] text-neutral-500">{pair.label}</p>
			<BorderBeam colorFrom={pair.from} colorTo={pair.to} />
		</div>
	{/each}
</div>
```

### Animation Speed

Time for one lap of the border.

```svelte
<script lang="ts">
	import { BorderBeam } from "fancy-ui-svelte";

	const speeds = [
		{ label: "Brisk · 5s", duration: 5 },
		{ label: "Default · 9s", duration: 9 },
		{ label: "Drift · 20s", duration: 20 },
	];
</script>

<div class="flex flex-wrap justify-center gap-6">
	{#each speeds as speed (speed.label)}
		<div
			class="relative flex h-32 w-48 items-end overflow-hidden rounded-xl border border-black/[0.08] bg-[#fafafa] p-4 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
		>
			<p class="font-mono text-[11px] text-neutral-500">{speed.label}</p>
			<BorderBeam duration={speed.duration} />
		</div>
	{/each}
</div>
```

### Size & Width

The pool of light around the head, and the hairline's thickness.

```svelte
<script lang="ts">
	import { BorderBeam } from "fancy-ui-svelte";

	const variants = [
		{ label: "Tight pool · 100", size: 100, borderWidth: 1.5 },
		{ label: "Wide pool · 320", size: 320, borderWidth: 1.5 },
		{ label: "Border · 3px", size: 200, borderWidth: 3 },
	];
</script>

<div class="flex flex-wrap justify-center gap-6">
	{#each variants as v (v.label)}
		<div
			class="relative flex h-32 w-48 items-end overflow-hidden rounded-xl border border-black/[0.08] bg-[#fafafa] p-4 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
		>
			<p class="font-mono text-[11px] text-neutral-500">{v.label}</p>
			<BorderBeam size={v.size} borderWidth={v.borderWidth} />
		</div>
	{/each}
</div>
```

### Tail & Glow

A short or long tail, with or without the bloom.

```svelte
<script lang="ts">
	import { BorderBeam } from "fancy-ui-svelte";

	const variants = [
		{ label: "Short tail · 0.1", tail: 0.1, glow: 0.6 },
		{ label: "Long tail · 0.6", tail: 0.6, glow: 0.6 },
		{ label: "No bloom · glow 0", tail: 0.25, glow: 0 },
	];
</script>

<div class="flex flex-wrap justify-center gap-6">
	{#each variants as v (v.label)}
		<div
			class="relative flex h-32 w-48 items-end overflow-hidden rounded-xl border border-black/[0.08] bg-[#fafafa] p-4 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
		>
			<p class="font-mono text-[11px] text-neutral-500">{v.label}</p>
			<BorderBeam tail={v.tail} glow={v.glow} />
		</div>
	{/each}
</div>
```

### Multiple Beams

Two comets half a lap apart, one reversed, passing each other.

```svelte
<script lang="ts">
	import { BorderBeam } from "fancy-ui-svelte";
</script>

<!-- Two comets on the same rail: one clockwise, one counter-clockwise, half a lap apart. -->
<div
	class="relative mx-auto flex h-40 w-full max-w-md items-center justify-center overflow-hidden rounded-xl border border-black/[0.08] bg-[#fafafa] p-6 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
>
	<p class="text-sm text-neutral-500">Two comets, passing</p>
	<BorderBeam colorFrom="#8ec5ff" colorTo="#c084fc" duration={10} />
	<BorderBeam colorFrom="#fcd9a8" colorTo="#f472b6" duration={10} delay={5} reverse />
</div>
```

### Interactive Playground

```svelte
<script lang="ts">
	import { BorderBeam, type BorderBeamProps } from "fancy-ui-svelte";
	import PropsPlayground from "$lib/components/PropsPlayground.svelte";
</script>

<PropsPlayground
	controls={[
		{ key: "tail", type: "range", label: "Tail", min: 0.05, max: 1, step: 0.05 },
		{ key: "glow", type: "range", label: "Glow", min: 0, max: 1, step: 0.05 },
		{ key: "reverse", type: "boolean", label: "Reverse" },
		{ key: "size", type: "range", label: "Size", min: 50, max: 500, step: 10 },
		{ key: "duration", type: "range", label: "Duration (s)", min: 1, max: 60 },
		{ key: "borderWidth", type: "range", label: "Border Width", min: 0.5, max: 8, step: 0.5 },
		{ key: "anchor", type: "range", label: "Anchor", min: 0, max: 100 },
		{ key: "colorFrom", type: "color", label: "Color From" },
		{ key: "colorTo", type: "color", label: "Color To" },
		{ key: "delay", type: "number", label: "Delay (s)", min: 0 },
	]}
	initialValues={{
		tail: 0.25,
		glow: 0.6,
		reverse: false,
		size: 200,
		duration: 9,
		borderWidth: 1.5,
		anchor: 90,
		colorFrom: "#8ec5ff",
		colorTo: "#c084fc",
		delay: 0,
	}}
>
	{#snippet preview(values)}
		<div
			class="relative flex h-40 w-[28rem] max-w-[80vw] items-center justify-center overflow-hidden rounded-xl border border-black/[0.08] bg-[#fafafa] p-6 dark:border-white/[0.08] dark:bg-[#0b0b0c]"
		>
			<p class="font-mono text-xs text-neutral-500">Preview</p>
			<BorderBeam {...values as BorderBeamProps} />
		</div>
	{/snippet}
</PropsPlayground>
```
