Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A component for creating animated border beam effects around elements with customizable gradients, duration, and direction.
motion-sv
Login
Enter your credentials to access your account.
border-beam.svelte
<script lang="ts"> import { BorderBeam } from "$lib/components/magic/border-beam/index.js"; import Button from "$lib/components/ui/button/button.svelte"; import * as Card from "$lib/components/ui/card/index.js"; import Input from "$lib/components/ui/input/input.svelte"; import Label from "$lib/components/ui/label/label.svelte";</script>
<Card.Root class="relative w-87.5 overflow-hidden"> <Card.Header> <Card.Title>Login</Card.Title> <Card.Description>Enter your credentials to access your account.</Card.Description> </Card.Header> <Card.Content> <form> <div class="grid w-full items-center gap-4"> <div class="flex flex-col space-y-1.5"> <Label for="email">Email</Label> <Input id="email" type="email" placeholder="Enter your email" /> </div> <div class="flex flex-col space-y-1.5"> <Label for="password">Password</Label> <Input id="password" type="password" placeholder="Enter your password" /> </div> </div> </form> </Card.Content> <Card.Footer class="flex justify-between"> <Button variant="outline">Register</Button> <Button>Login</Button> </Card.Footer> <BorderBeam duration={8} size={100} /></Card.Root>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/border-beam.json
Install dependencies
Install the required packages for this component:
pnpm add motion-sv
Copy the Source Code
Copy and paste the following code into your project:
border-beam.svelte
<script lang="ts"> import type { ClassValue } from "svelte/elements"; import { motion, type Transition } from "motion-sv"; import { cn } from "#lib/utils.js";
interface BorderBeamProps { size?: number; duration?: number; delay?: number; colorFrom?: string; colorTo?: string; transition?: Transition; class?: ClassValue; style?: string; reverse?: boolean; initialOffset?: number; borderWidth?: number; }
let { class: className, size = 50, delay = 0, duration = 6, colorFrom = "#ffaa40", colorTo = "#9c40ff", transition, reverse = false, initialOffset = 0, borderWidth = 1, }: BorderBeamProps = $props();
const containerStyle = $derived(`--border-beam-width: ${borderWidth}px;`);
const beamStyle = $derived({ width: size, offsetPath: `rect(0 auto auto 0 round ${size}px)`, "--color-from": colorFrom, "--color-to": colorTo, } as any);
const animateConfig = $derived({ offsetDistance: reverse ? [`${100 - initialOffset}%`, `${-initialOffset}%`] : [`${initialOffset}%`, `${100 + initialOffset}%`], });
const transitionConfig = $derived({ repeat: Infinity, ease: "linear" as const, duration, delay: -delay, ...transition, } as any);</script>
<div class="pointer-events-none absolute inset-0 rounded-[inherit] border-(length:--border-beam-width) border-transparent mask-[linear-gradient(transparent,transparent),linear-gradient(#000,#000)] mask-intersect [mask-clip:padding-box,border-box]" style={containerStyle}> <motion.div class={cn( "absolute aspect-square", "bg-linear-to-l from-(--color-from) via-(--color-to) to-transparent", className )} style={beamStyle} initial={{ offsetDistance: `${initialOffset}%` }} animate={animateConfig} transition={transitionConfig} /></div> index.ts
import BorderBeam from "./border-beam.svelte";export { BorderBeam };Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── border-beam/ ├── border-beam.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/border-beam/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { BorderBeam } from "#lib/components/magic/border-beam/index.js";</script>
<div class="relative overflow-hidden rounded-xl border p-8"> Border beam <BorderBeam /></div>Examples
2 Border Beams
Now Playing
Stairway to Heaven - Led Zeppelin
2:45 8:02
border-beam-two.svelte
<script lang="ts"> import { BorderBeam } from "$lib/components/magic/border-beam/index.js"; import Button from "$lib/components/ui/button/button.svelte"; import * as Card from "$lib/components/ui/card/index.js";
import Play from "@lucide/svelte/icons/play"; import SkipBack from "@lucide/svelte/icons/skip-back"; import SkipForward from "@lucide/svelte/icons/skip-forward";</script>
<Card.Root class="relative w-87.5 overflow-hidden"> <Card.Header> <Card.Title>Now Playing</Card.Title> <Card.Description>Stairway to Heaven - Led Zeppelin</Card.Description> </Card.Header> <Card.Content> <div class="flex flex-col items-center gap-4"> <div class="h-48 w-48 rounded-lg bg-linear-to-br from-purple-500 to-pink-500"></div>
<div class="bg-secondary h-1 w-full rounded-full"> <div class="bg-primary h-full w-1/3 rounded-full"></div> </div> <div class="text-muted-foreground flex w-full justify-between text-sm"> <span>2:45</span> <span>8:02</span> </div> </div> </Card.Content> <Card.Footer class="flex justify-center gap-4"> <Button variant="outline" size="icon" class="rounded-full"> <SkipBack class="size-4" /> </Button> <Button size="icon" class="rounded-full"> <Play class="size-4" /> </Button> <Button variant="outline" size="icon" class="rounded-full"> <SkipForward class="size-4" /> </Button> </Card.Footer> <BorderBeam duration={6} size={400} class="from-transparent via-red-500 to-transparent" /> <BorderBeam duration={6} delay={3} size={400} borderWidth={2} class="from-transparent via-blue-500 to-transparent" /></Card.Root>Reverse
Login
Enter your credentials to access your account.
border-beam-reverse.svelte
<script lang="ts"> import { BorderBeam } from "$lib/components/magic/border-beam/index.js"; import Button from "$lib/components/ui/button/button.svelte"; import * as Card from "$lib/components/ui/card/index.js"; import Input from "$lib/components/ui/input/input.svelte"; import Label from "$lib/components/ui/label/label.svelte";</script>
<Card.Root class="relative w-87.5 overflow-hidden"> <Card.Header> <Card.Title>Login</Card.Title> <Card.Description>Enter your credentials to access your account.</Card.Description> </Card.Header> <Card.Content> <form> <div class="grid w-full items-center gap-4"> <div class="flex flex-col space-y-1.5"> <Label for="email">Email</Label> <Input id="email" type="email" placeholder="Enter your email" /> </div> <div class="flex flex-col space-y-1.5"> <Label for="password">Password</Label> <Input id="password" type="password" placeholder="Enter your password" /> </div> </div> </form> </Card.Content> <Card.Footer class="flex justify-between"> <Button variant="outline">Register</Button> <Button>Login</Button> </Card.Footer> <BorderBeam duration={4} size={300} reverse class="from-transparent via-green-500 to-transparent" /></Card.Root>Spring
border-beam-spring.svelte
<script lang="ts"> import { BorderBeam } from "$lib/components/magic/border-beam/index.js"; import { Button } from "$lib/components/ui/button/index.js";</script>
<Button class="relative overflow-hidden" size="lg" variant="outline"> Buy Now <BorderBeam size={40} initialOffset={20} class="from-transparent via-yellow-500 to-transparent" transition={{ type: "spring", stiffness: 60, damping: 20, }} /></Button>Props
Border Beam
A component for creating animated border beam effects.
| Name | Type | Default | Description |
|---|---|---|---|
size | number | 50 | The size of the border beam in pixels |
duration | number | 6 | The duration of the animation in seconds |
delay | number | 0 | The delay before the animation starts in seconds |
colorFrom | string | "#ffaa40" | The starting color of the gradient |
colorTo | string | "#9c40ff" | The ending color of the gradient |
transition | Transition | undefined | Custom motion transition configuration |
class | ClassValue | undefined | Additional CSS classes to apply |
style | string | undefined | Additional inline styles |
reverse | boolean | false | Whether to reverse the animation direction |
initialOffset | number | 0 | The initial offset position (0-100) |
borderWidth | number | 1 | The border width of the beam in pixels |