Shine Border
A React shine border: a thin outline with a soft, multi-color sheen gliding around any card, badge or panel. Built with Motion and Tailwind CSS, it follows the real rounded shape at any aspect ratio, pauses off-screen and stays still for prefers-reduced-motion.
- Multi-color sheen
- Any aspect ratio
- Pauses off-screen
- No layout shift
- prefers-reduced-motion
Team plan
$24 per seat, billed monthly
Shared projects, role-based access and audit logs for your whole team.
import { ShineBorder } from "@/components/dusk/shine-border/shine-border";
export default function ShineBorderDemo() {
return (
<ShineBorder
className="w-full max-w-sm"
color={["#c4b5fd", "#7dd3fc"]}
contentClassName="p-6"
>
<p className="text-sm font-medium text-white/60">Team plan</p>
<p className="mt-2 text-xl font-semibold">$24 per seat, billed monthly</p>
<p className="mt-2 text-sm leading-relaxed text-white/60">
Shared projects, role-based access and audit logs for your whole team.
</p>
</ShineBorder>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/shine-border.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/shine-border/shine-border.tsx.shine-border.tsx "use client"; import * as React from "react"; import { animate, motion, useInView, useMotionValue, useReducedMotion, } from "motion/react"; import { cn } from "@/lib/utils"; export interface ShineBorderProps extends Omit<React.ComponentProps<"div">, "color"> { /** One CSS color, or several that blend from the sheen's core outwards. */ color?: string | string[]; /** Border width in px. */ borderWidth?: number; /** Seconds for the sheen to travel once around the border. */ duration?: number; /** Corner radius in px. */ radius?: number; /** Classes for the inner content wrapper, which paints its own background. */ contentClassName?: string; } /** Masks a layer down to its padding box, leaving only a ring the width of its padding. */ const RING = "pointer-events-none absolute inset-0 rounded-[inherit] [mask-image:linear-gradient(#000_0_0),linear-gradient(#000_0_0)] [mask-clip:content-box,border-box] [mask-composite:exclude]"; /** * Point at fraction `t` (0–1) of the way around a rounded rectangle, walking * clockwise from the top-left corner. Moves at constant speed on every side. */ function pointOnRoundedRect(t: number, w: number, h: number, r: number) { const rad = Math.max(0, Math.min(r, w / 2, h / 2)); const sx = w - 2 * rad; const sy = h - 2 * rad; const arc = (Math.PI / 2) * rad; const segments = [sx, arc, sy, arc, sx, arc, sy, arc]; const total = segments.reduce((a, b) => a + b, 0) || 1; let d = (((t % 1) + 1) % 1) * total; for (let i = 0; i < segments.length; i++) { const len = segments[i]; if (d > len && i < segments.length - 1) { d -= len; continue; } const k = len === 0 ? 0 : d / len; const corner = (cx: number, cy: number, start: number) => { const a = start + k * (Math.PI / 2); return { x: cx + rad * Math.cos(a), y: cy + rad * Math.sin(a) }; }; switch (i) { case 0: return { x: rad + k * sx, y: 0 }; case 1: return corner(w - rad, rad, -Math.PI / 2); case 2: return { x: w, y: rad + k * sy }; case 3: return corner(w - rad, h - rad, 0); case 4: return { x: w - rad - k * sx, y: h }; case 5: return corner(rad, h - rad, Math.PI / 2); case 6: return { x: 0, y: h - rad - k * sy }; default: return corner(rad, rad, Math.PI); } } return { x: 0, y: 0 }; } /** * Wraps content in a thin border with a soft, multi-color sheen gliding around it. */ export function ShineBorder({ color = "var(--color-primary)", borderWidth = 1, duration = 8, radius = 12, className, contentClassName, style, children, ...props }: ShineBorderProps) { const ref = React.useRef<HTMLDivElement>(null); const size = React.useRef({ w: 0, h: 0 }); const reduceMotion = useReducedMotion(); const inView = useInView(ref); const progress = useMotionValue(0); const background = useMotionValue("none"); const colors = Array.isArray(color) ? (color.length ? color : ["var(--color-primary)"]) : [color]; // Colors spread from the core of the sheen to ~45% of its radius, then fade out. const stops = colors .map((c, i) => `${c} ${colors.length === 1 ? 0 : Math.round((i / (colors.length - 1)) * 45)}%`) .join(", "); const reversed = [...colors] .reverse() .map((c, i) => `${c} ${colors.length === 1 ? 0 : Math.round((i / (colors.length - 1)) * 45)}%`) .join(", "); // Builds the two-spot gradient from the current progress and element size. const paint = React.useCallback(() => { const { w, h } = size.current; if (!w || !h) return; const t = progress.get(); const inset = borderWidth / 2; const iw = w - borderWidth; const ih = h - borderWidth; const r = Math.max(0, radius - inset); const a = pointOnRoundedRect(t, iw, ih, r); const b = pointOnRoundedRect(t + 0.5, iw, ih, r); const spot = Math.round(Math.max(40, Math.min(Math.min(w, h) * 0.9, 160))); background.set( `radial-gradient(${spot}px circle at ${a.x + inset}px ${a.y + inset}px, ${stops}, transparent 72%),` + ` radial-gradient(${spot}px circle at ${b.x + inset}px ${b.y + inset}px, ${reversed}, transparent 72%)` ); }, [background, borderWidth, progress, radius, reversed, stops]); // Track the element's size so the path matches its shape at any aspect ratio. React.useEffect(() => { const el = ref.current; if (!el) return; const observer = new ResizeObserver(([entry]) => { const box = entry.borderBoxSize?.[0]; size.current = box ? { w: box.inlineSize, h: box.blockSize } : { w: el.offsetWidth, h: el.offsetHeight }; paint(); }); observer.observe(el); return () => observer.disconnect(); }, [paint]); React.useEffect(() => progress.on("change", paint), [paint, progress]); // Glide only while visible; reduced motion keeps the sheen parked. React.useEffect(() => { if (reduceMotion) { progress.set(0.125); paint(); return; } if (!inView) return; const controls = animate(progress, progress.get() + 1, { duration: Math.max(1, duration), ease: "linear", repeat: Infinity, }); return () => controls.stop(); }, [duration, inView, paint, progress, reduceMotion]); return ( <div ref={ref} data-slot="shine-border" className={cn("relative isolate", className)} style={{ borderRadius: radius, padding: borderWidth, ...style }} {...props} > {/* Faint resting line so the edge reads where the sheen isn't. */} <span aria-hidden className={RING} style={{ padding: borderWidth, background: "color-mix(in oklab, white 10%, transparent)" }} /> <motion.span aria-hidden className={RING} style={{ padding: borderWidth, background }} /> <div data-slot="shine-border-content" className={cn("relative h-full bg-card", contentClassName)} style={{ borderRadius: Math.max(0, radius - borderWidth) }} > {children} </div> </div> ); }
Usage
import { ShineBorder } from "@/components/dusk/shine-border/shine-border"
export function PromoCard() {
return (
<ShineBorder color={["#a78bfa", "#22d3ee"]} contentClassName="p-6">
<h3 className="font-semibold">Upgrade to Pro</h3>
<p className="text-sm text-white/60">Unlock every animated block.</p>
</ShineBorder>
)
}Examples
Colors
color takes one CSS color or an array. Multiple colors blend from the core of the sheen outwards; a second sheen runs half a lap behind with the colors reversed.
Mint
Single color
Warm
2 colors
Cool
2 colors
import { ShineBorder } from "@/components/dusk/shine-border/shine-border";
const cards = [
{ title: "Mint", color: "var(--color-primary)" },
{ title: "Warm", color: ["#fda4af", "#fcd34d"] },
{ title: "Cool", color: ["#7dd3fc", "#c4b5fd"] },
];
export default function ShineBorderColorsDemo() {
return (
<div className="grid w-full max-w-2xl gap-4 sm:grid-cols-3">
{cards.map((card) => (
<ShineBorder key={card.title} color={card.color} contentClassName="p-5">
<p className="font-semibold">{card.title}</p>
<p className="mt-1 text-sm text-white/60">
{Array.isArray(card.color) ? `${card.color.length} colors` : "Single color"}
</p>
</ShineBorder>
))}
</div>
);
}Width, speed & shape
borderWidth sets the line thickness, duration the seconds per lap and radius the corner radius — a large radius gives a pill.
Thicker border
borderWidth 2, duration 6
import { ShineBorder } from "@/components/dusk/shine-border/shine-border";
export default function ShineBorderWidthDemo() {
return (
<>
<ShineBorder radius={9999} duration={5} color={["#fde68a", "#fdba74"]}>
<span className="block px-4 py-1.5 text-sm font-medium">Now in public beta</span>
</ShineBorder>
<ShineBorder borderWidth={2} duration={6} color={["#f9a8d4", "#a5b4fc"]}>
<div className="px-8 py-6 text-center">
<p className="text-lg font-semibold">Thicker border</p>
<p className="text-sm text-white/60">borderWidth 2, duration 6</p>
</div>
</ShineBorder>
</>
);
}API Reference
Also accepts every <div> prop. The content wrapper paints bg-card by default; override it with contentClassName.
| Prop | Type | Default | Description |
|---|---|---|---|
| color | string | string[] | var(--color-primary) | One CSS color, or several that blend from the sheen's core outwards. |
| borderWidth | number | 1 | Border width in px. |
| duration | number | 8 | Seconds for the sheen to travel once around the border. |
| radius | number | 12 | Corner radius in px. |
| contentClassName | string | — | Classes for the inner content wrapper (padding, background). |
| className | string | — | Classes for the outer wrapper, merged with tailwind-merge. |
Accessibility
- The border layers are aria-hidden and absolutely positioned, so they never reach screen readers or change the size of the content.
- Content is rendered as-is: links, buttons and headings inside keep their own semantics and focus styles.
- With prefers-reduced-motion the sheen is parked in one place instead of moving; it also pauses whenever the element is off-screen.
- Animation runs on Motion values, so it never re-renders React and is cleaned up on unmount.