# Weld — Animated Button for React

> A light beam traveling the border in a continuous loop like a welding arc: a blinding white-hot head with a cool blue-white tail, corner sparks, and a fading heat discoloration. Pure CSS, corner-radius aware via offset-path.

- Page: https://crucibleui.com/components/buttons/weld
- Category: [buttons](https://crucibleui.com/components/buttons)
- Tier: free (full source)
- Engine: css

## Install

```bash
npx shadcn@latest add @crucible/weld
```

Registry JSON: https://crucibleui.com/r/weld.json

Import from `@/components/crucible/weld`.

## Props (`WeldProps`)

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `headColor?` | `string` | `white` | Color of the blinding beam head. Any CSS color. |
| `tailColor?` | `string` | `cool blue-white` | Color of the tail trailing the head. |
| `duration?` | `number` | `3.2` | Seconds for one full lap of the border. |
| `radius?` | `number` | `10` | Border radius in px — the beam's path is corner-radius aware and matches this exactly. |
| `reverse?` | `boolean` | `false` | Travel counterclockwise instead of clockwise. |
| `delay?` | `number` | `0` | Seconds to wait before the first lap starts. |
| `paused?` | `boolean` | `false` | Freeze the animation, holding the current frame. |

Also accepts: `React.ComponentPropsWithoutRef<"button">`.

## Usage example

```tsx
import { Weld } from "@/components/crucible/weld";

const LABEL = "text-[10px] font-medium uppercase tracking-[0.2em] text-neutral-600";

export default function WeldDemo() {
  return (
    <div className="relative isolate flex h-full min-h-[360px] w-full items-center justify-center overflow-hidden rounded-xl bg-neutral-950">
      <div
        aria-hidden
        className="pointer-events-none absolute inset-0 bg-[radial-gradient(ellipse_at_center,rgba(255,255,255,0.035),transparent_70%)]"
      />
      <div className="relative z-10 flex flex-col items-center gap-10">
        <div className="flex flex-wrap items-end justify-center gap-10">
          <div className="flex flex-col items-center gap-3">
            <Weld radius={10}>Get started</Weld>
            <span className={LABEL}>Default</span>
          </div>
          <div className="flex flex-col items-center gap-3">
            <Weld radius={999} duration={2.2} headColor="#fde68a" tailColor="#f59e0b">
              Continue
            </Weld>
            <span className={LABEL}>Custom colors · pill</span>
          </div>
          <div className="flex flex-col items-center gap-3">
            <Weld radius={4} reverse>
              Go back
            </Weld>
            <span className={LABEL}>Reverse</span>
          </div>
        </div>
        <p className="text-sm text-neutral-500">The beam loops the border continuously.</p>
      </div>
    </div>
  );
}
```

## Accessibility & performance

Honors `prefers-reduced-motion` with a designed static frame or fade (never a blank box) and passes `className` through.

## Source (`weld.tsx`)

```tsx
import * as React from "react";

import { cn } from "@/lib/utils";

export interface WeldProps extends React.ComponentPropsWithoutRef<"button"> {
  /** Color of the blinding beam head. Any CSS color. @default white */
  headColor?: string;
  /** Color of the tail trailing the head. @default cool blue-white */
  tailColor?: string;
  /** Seconds for one full lap of the border. @default 3.2 */
  duration?: number;
  /** Border radius in px — the beam's path is corner-radius aware and matches this exactly. @default 10 */
  radius?: number;
  /** Travel counterclockwise instead of clockwise. @default false */
  reverse?: boolean;
  /** Seconds to wait before the first lap starts. @default 0 */
  delay?: number;
  /** Freeze the animation, holding the current frame. @default false */
  paused?: boolean;
}

/**
 * Weld — a light beam traveling the border in a continuous loop, like a
 * welding arc tracing the seam: a blinding white-hot head with a cool
 * blue-white tail, corner sparks, and a faint heat-discoloration on the rim
 * that fades before the next lap. Pure CSS, corner-radius aware via
 * `offset-path`. Honors prefers-reduced-motion by freezing the beam in place.
 */
export function Weld({
  headColor = "#ffffff",
  tailColor = "#93c5fd",
  duration = 3.2,
  radius = 10,
  reverse = false,
  delay = 0,
  paused = false,
  className,
  style,
  disabled,
  children,
  ...rest
}: WeldProps) {
  return (
    <button
      data-crucible="weld"
      className={cn(
        "relative isolate inline-flex items-center justify-center overflow-visible",
        "border border-neutral-800 bg-neutral-900 px-6 py-3 text-sm font-medium text-white",
        "select-none",
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950",
        "focus-visible:ring-[color:var(--weld-head)]",
        "disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      style={
        {
          "--weld-head": headColor,
          "--weld-tail": tailColor,
          "--weld-duration": `${duration}s`,
          "--weld-delay": `${delay}s`,
          "--weld-direction": reverse ? "reverse" : "normal",
          "--weld-play": paused ? "paused" : "running",
          "--weld-radius": `${radius}px`,
          borderRadius: radius,
          ...style,
        } as React.CSSProperties
      }
      disabled={disabled}
      {...rest}
    >
      <style>{`
        @keyframes crucible-weld-travel {
          to { offset-distance: 100%; }
        }
        @keyframes crucible-weld-spark {
          0%, 92%, 100% { opacity: 0; transform: scale(0.4); }
          95% { opacity: 1; transform: scale(1); }
        }
        @keyframes crucible-weld-heat {
          0%   { opacity: 0; }
          6%   { opacity: 0.9; }
          30%  { opacity: 0; }
          100% { opacity: 0; }
        }
        [data-crucible="weld"] .weld-track {
          position: absolute;
          inset: 0;
          offset-path: inset(0 round var(--weld-radius));
          offset-distance: 0%;
          animation: crucible-weld-travel var(--weld-duration) linear infinite;
          animation-delay: var(--weld-delay);
          animation-direction: var(--weld-direction);
          animation-play-state: var(--weld-play);
        }
        /* The track box is exactly container-sized so its own perimeter IS the
           button's border; offset-distance rides that perimeter by moving the
           box's center anchor. Centering the head/tail on that anchor makes
           them ride the path while the (invisible) track box itself overflows. */
        [data-crucible="weld"] .weld-track { offset-rotate: auto; }
        [data-crucible="weld"] .weld-head,
        [data-crucible="weld"] .weld-trail-dot {
          position: absolute;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          border-radius: 999px;
        }
        [data-crucible="weld"] .weld-head {
          width: 7px;
          height: 7px;
          /* A tight white-hot core so the beam reads as a point riding the
             seam, not a loose orb hovering off the edge. */
          background: radial-gradient(circle, #fff 0%, var(--weld-head) 30%, var(--weld-tail) 62%, transparent 80%);
          filter: blur(0.3px);
          box-shadow: 0 0 5px 1px color-mix(in oklab, var(--weld-head) 85%, transparent),
            0 0 11px 2px color-mix(in oklab, var(--weld-tail) 45%, transparent);
        }
        /* The tail is drip dots on their own tracks, phase-lagged behind the
           head via negative animation-delays — they ride the same offset-path,
           so the trail bends around corners instead of flying off tangentially
           like a straight gradient bar would. */
        [data-crucible="weld"] .weld-trail-dot {
          background: var(--weld-tail);
          filter: blur(0.4px);
          box-shadow: 0 0 4px 1px color-mix(in oklab, var(--weld-tail) 55%, transparent);
        }
        [data-crucible="weld"] .weld-corner {
          position: absolute;
          width: 4px;
          height: 4px;
          border-radius: 999px;
          background: var(--weld-head);
          box-shadow: 0 0 5px 1px color-mix(in oklab, var(--weld-tail) 60%, transparent);
          animation: crucible-weld-spark var(--weld-duration) linear infinite;
          /* backwards: adopt the 0% keyframe (opacity 0) during the staggered
             start delay, so delayed corners stay dark on mount instead of
             flashing at their base opacity 1 until their animation begins. */
          animation-fill-mode: backwards;
          animation-play-state: var(--weld-play);
          transform: translate(-50%, -50%);
        }
        [data-crucible="weld"] .weld-heat {
          position: absolute;
          inset: 0;
          border-radius: inherit;
          box-shadow: inset 0 0 0 1.5px color-mix(in oklab, var(--weld-tail) 55%, transparent);
          animation: crucible-weld-heat var(--weld-duration) ease-out infinite;
          animation-delay: var(--weld-delay);
          /* backwards so a non-zero delay holds the rim at the 0% keyframe
             (opacity 0) rather than its base opacity 1 during the wait. */
          animation-fill-mode: backwards;
          animation-play-state: var(--weld-play);
        }
        [data-crucible="weld"]:disabled .weld-track,
        [data-crucible="weld"]:disabled .weld-corner,
        [data-crucible="weld"]:disabled .weld-heat {
          animation-play-state: paused;
        }
        @media (prefers-reduced-motion: reduce) {
          [data-crucible="weld"] .weld-track,
          [data-crucible="weld"] .weld-corner,
          [data-crucible="weld"] .weld-heat {
            animation: none;
          }
          [data-crucible="weld"] .weld-track { offset-distance: 0%; }
          [data-crucible="weld"] .weld-heat { opacity: 0.25; }
          [data-crucible="weld"] .weld-corner { opacity: 0; }
        }
      `}</style>

      {/* Faint heat discoloration that blooms after the beam passes and fades before the next lap. */}
      <span aria-hidden className="weld-heat pointer-events-none" />

      {/* Corner sparks, roughly phase-locked to the beam reaching each corner. */}
      {/* Counterclockwise laps reach the top-right / bottom-left corners in the
          opposite order, so their phases swap when reversed. */}
      <span aria-hidden className="weld-corner pointer-events-none" style={{ top: 0, left: 0, animationDelay: `calc(var(--weld-delay) + var(--weld-duration) * 0.0)` }} />
      <span aria-hidden className="weld-corner pointer-events-none" style={{ top: 0, right: 0, animationDelay: `calc(var(--weld-delay) + var(--weld-duration) * ${reverse ? 0.75 : 0.25})` }} />
      <span aria-hidden className="weld-corner pointer-events-none" style={{ bottom: 0, right: 0, animationDelay: `calc(var(--weld-delay) + var(--weld-duration) * 0.5)` }} />
      <span aria-hidden className="weld-corner pointer-events-none" style={{ bottom: 0, left: 0, animationDelay: `calc(var(--weld-delay) + var(--weld-duration) * ${reverse ? 0.25 : 0.75})` }} />

      {/* The beam itself: a bright head trailed by drip dots, all riding the
          border path. Negative delays put each dot mid-lap immediately (no
          start-corner pileup) at a phase just behind the head. */}
      {[
        { lag: 0.008, size: 5, opacity: 0.85 },
        { lag: 0.018, size: 4, opacity: 0.6 },
        { lag: 0.03, size: 3.5, opacity: 0.4 },
        { lag: 0.044, size: 3, opacity: 0.22 },
      ].map(({ lag, size, opacity }) => (
        <span
          key={lag}
          aria-hidden
          className="weld-track pointer-events-none"
          style={{ animationDelay: `calc(var(--weld-delay) - var(--weld-duration) * ${1 - lag})` }}
        >
          <span className="weld-trail-dot" style={{ width: size, height: size, opacity }} />
        </span>
      ))}
      <span aria-hidden className="weld-track pointer-events-none">
        <span className="weld-head" />
      </span>

      <span className="relative z-10">{children}</span>
    </button>
  );
}
```
