# Galvanize — Animated Button for React

> An animated gradient border cycling silver to blue to violet, like electroplating in progress. Hover accelerates the rotation and thickens the ring by a pixel. Pure CSS via a masked conic gradient.

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

## Install

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

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

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

## Props (`GalvanizeProps`)

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `colors?` | `[string, string, string]` | `silver, blue, violet` | Three colors the border rotates through. Any CSS colors. |
| `radius?` | `number` | `12` | Border radius in px. |
| `thickness?` | `number` | `1.5` | Ring thickness in px at rest — thickens by 1px on hover. |
| `duration?` | `number` | `5` | Seconds for one full rotation at rest (hover runs ~2.9x faster). |
| `paused?` | `boolean` | `false` | Freeze the animation, holding the current frame. |

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

## Usage example

```tsx
import { Galvanize } from "@/components/crucible/galvanize";

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

export default function GalvanizeDemo() {
  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">
            <Galvanize>Get started</Galvanize>
            <span className={LABEL}>Default</span>
          </div>
          <div className="flex flex-col items-center gap-3">
            <Galvanize radius={999} thickness={2} duration={3} colors={["#fbbf24", "#fb7185", "#a78bfa"]}>
              Continue
            </Galvanize>
            <span className={LABEL}>Custom colors · pill</span>
          </div>
          <div className="flex flex-col items-center gap-3">
            <Galvanize disabled>Disabled</Galvanize>
            <span className={LABEL}>Disabled</span>
          </div>
        </div>
        <p className="text-sm text-neutral-500">Hover — the rotation accelerates and the ring thickens.</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 (`galvanize.tsx`)

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

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

export interface GalvanizeProps extends React.ComponentPropsWithoutRef<"button"> {
  /** Three colors the border rotates through. Any CSS colors. @default silver, blue, violet */
  colors?: [string, string, string];
  /** Border radius in px. @default 12 */
  radius?: number;
  /** Ring thickness in px at rest — thickens by 1px on hover. @default 1.5 */
  thickness?: number;
  /** Seconds for one full rotation at rest (hover runs ~2.9x faster). @default 5 */
  duration?: number;
  /** Freeze the animation, holding the current frame. @default false */
  paused?: boolean;
}

/**
 * Galvanize — an animated gradient border, like electroplating in progress.
 * Silver, blue, and violet rotate continuously around the edge; on hover
 * the rotation visibly accelerates and the ring thickens by a pixel, as if
 * current had increased. Pure CSS via a masked conic gradient — the
 * gradient never bleeds into the label. Honors prefers-reduced-motion by
 * freezing the ring at a static tri-tone gradient.
 */
export function Galvanize({
  colors = ["#cbd5e1", "#60a5fa", "#8b5cf6"],
  radius = 12,
  thickness = 1.5,
  duration = 5,
  paused = false,
  className,
  style,
  disabled,
  children,
  ...rest
}: GalvanizeProps) {
  return (
    <button
      data-crucible="galvanize"
      className={cn(
        "relative isolate inline-flex items-center justify-center overflow-hidden",
        "bg-neutral-900 px-6 py-3 text-sm font-medium text-white",
        "select-none transition-colors",
        "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-offset-neutral-950",
        "focus-visible:ring-[color:var(--galvanize-c1)]",
        "disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      style={
        {
          "--galvanize-c1": colors[0],
          "--galvanize-c2": colors[1],
          "--galvanize-c3": colors[2],
          "--galvanize-thickness": `${thickness}px`,
          "--galvanize-duration": `${duration}s`,
          "--galvanize-play": paused ? "paused" : "running",
          borderRadius: radius,
          ...style,
        } as React.CSSProperties
      }
      disabled={disabled}
      {...rest}
    >
      <style>{`
        @property --galvanize-angle {
          syntax: "<angle>";
          inherits: false;
          initial-value: 0deg;
        }
        @keyframes crucible-galvanize-rotate {
          to { --galvanize-angle: 360deg; }
        }
        /* The rotating conic lives ON the ring element (not an oversized child),
           so the border fills evenly at any button aspect ratio — animating the
           gradient's start angle rather than transform-rotating a rectangle. */
        [data-crucible="galvanize"] .galvanize-ring {
          position: absolute;
          inset: 0;
          border-radius: inherit;
          padding: var(--galvanize-thickness);
          transition: padding 200ms ease;
          background: conic-gradient(
            from var(--galvanize-angle),
            var(--galvanize-c1),
            var(--galvanize-c2),
            var(--galvanize-c3),
            var(--galvanize-c1)
          );
          -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite: exclude;
          animation: crucible-galvanize-rotate var(--galvanize-duration) linear infinite;
          animation-play-state: var(--galvanize-play);
        }
        [data-crucible="galvanize"]:hover .galvanize-ring {
          padding: calc(var(--galvanize-thickness) + 1px);
          animation-duration: calc(var(--galvanize-duration) * 0.35);
        }
        [data-crucible="galvanize"]:disabled .galvanize-ring {
          animation-play-state: paused;
        }
        @media (prefers-reduced-motion: reduce) {
          [data-crucible="galvanize"] .galvanize-ring {
            animation: none;
            background: conic-gradient(from 35deg, var(--galvanize-c1), var(--galvanize-c2), var(--galvanize-c3), var(--galvanize-c1));
          }
          [data-crucible="galvanize"]:hover .galvanize-ring {
            padding: var(--galvanize-thickness);
          }
        }
      `}</style>

      <span aria-hidden className="galvanize-ring pointer-events-none" />

      {/* Faint persistent rim over the gradient: keeps the silhouette readable
          (and lifts the dim ember/violet phases) no matter the spin phase. */}
      <span
        aria-hidden
        className="pointer-events-none absolute inset-0 rounded-[inherit] border border-white/15"
      />

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