# Gradient Border

Wraps a card, button, or field in a moving gradient border that spins, shines, or pulses, with an optional soft glow.

- Category: Backgrounds
- Status: stable
- Registry: https://markas.jenderalcorp.com/r/gradient-border.json
- CLI: `npx markasui@latest add gradient-border`

## When to use

Highlight one thing on the page: a featured plan, the main call to action, or an AI prompt field.

- Use it once or twice per screen so it keeps drawing attention
- Put padding on the content inside, not on the component
- Match radius to the content: full for pill buttons, lg for fields and small buttons

## Code

### Blade

Save at `resources/views/components/markas/gradient-border.blade.php`. No extra dependencies.

```blade
@props([
    'variant' => 'spin',
    'color' => 'primary',
    'speed' => 'normal',
    'radius' => 'xl',
    'glow' => false,
])

@php
    $base = 'relative isolate bg-line p-px';
    $layer = 'pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] [container-type:size]';
    $glowLayer = '-z-10 opacity-50 blur-lg';
    $inner = 'relative h-full bg-surface';
    $variants = [
        'spin' => 'absolute top-1/2 left-1/2 size-[calc(100cqw+100cqh)] -translate-x-1/2 -translate-y-1/2 animate-[markas-gb-spin_var(--markas-gb-duration)_linear_infinite] bg-[conic-gradient(transparent_0deg,currentColor_60deg,transparent_120deg,transparent_180deg,currentColor_240deg,transparent_300deg)] motion-reduce:animate-none',
        'shine' => 'absolute inset-y-0 left-0 w-1/3 translate-x-full -skew-x-12 animate-[markas-gb-shine_var(--markas-gb-duration)_ease-in-out_infinite] bg-[linear-gradient(90deg,transparent,currentColor,transparent)] motion-reduce:animate-none',
        'pulse' => 'absolute inset-0 animate-[markas-gb-pulse_var(--markas-gb-duration)_ease-in-out_infinite] bg-[conic-gradient(from_180deg,currentColor,transparent_30%,currentColor_50%,transparent_80%,currentColor)] motion-reduce:animate-none',
    ];
    $radii = [
        'lg' => ['outer' => 'rounded-lg', 'inner' => 'rounded-[7px]'],
        'xl' => ['outer' => 'rounded-xl', 'inner' => 'rounded-[11px]'],
        'full' => ['outer' => 'rounded-full', 'inner' => 'rounded-full'],
    ];
    $colors = [
        'muted' => 'text-muted',
        'primary' => 'text-primary',
        'success' => 'text-success',
        'warning' => 'text-warning',
        'danger' => 'text-danger',
    ];
    $speeds = ['slow' => '8s', 'normal' => '4s', 'fast' => '2s'];
    $keyframes = '@keyframes markas-gb-spin{to{rotate:360deg}}@keyframes markas-gb-shine{0%{translate:-100% 0}60%,100%{translate:400% 0}}@keyframes markas-gb-pulse{50%{opacity:.2}}';

    $shape = $radii[$radius] ?? $radii['xl'];
    $spinner = $variants[$variant] ?? $variants['spin'];
    $tone = $colors[$color] ?? $colors['primary'];
@endphp

<div {{ $attributes->merge(['style' => '--markas-gb-duration: '.($speeds[$speed] ?? $speeds['normal'])])->class([$base, $shape['outer']]) }}>
    <style>{!! $keyframes !!}</style>
    @if ($glow)
        <div aria-hidden="true" @class([$layer, $glowLayer, $tone])>
            <span class="{{ $spinner }}"></span>
        </div>
    @endif
    <div aria-hidden="true" @class([$layer, $tone])>
        <span class="{{ $spinner }}"></span>
    </div>
    <div @class([$inner, $shape['inner']])>{{ $slot }}</div>
</div>
```

```blade
<x-markas.gradient-border variant="spin" :glow="true" class="max-w-80">
    <div class="grid gap-3 p-6">
        <h3 class="text-lg font-semibold text-ink">Pro workspace</h3>
        <x-markas.button>Upgrade now</x-markas.button>
    </div>
</x-markas.gradient-border>
```

No JavaScript or Alpine.js needed.

### React

Save at `src/components/markas/GradientBorder.tsx`. No extra dependencies.

```tsx
import type { ComponentProps, CSSProperties } from "react";

const base = "relative isolate bg-line p-px";
const layer =
  "pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] [container-type:size]";
const glowLayer = "-z-10 opacity-50 blur-lg";
const inner = "relative h-full bg-surface";
const variants = {
  spin: "absolute top-1/2 left-1/2 size-[calc(100cqw+100cqh)] -translate-x-1/2 -translate-y-1/2 animate-[markas-gb-spin_var(--markas-gb-duration)_linear_infinite] bg-[conic-gradient(transparent_0deg,currentColor_60deg,transparent_120deg,transparent_180deg,currentColor_240deg,transparent_300deg)] motion-reduce:animate-none",
  shine:
    "absolute inset-y-0 left-0 w-1/3 translate-x-full -skew-x-12 animate-[markas-gb-shine_var(--markas-gb-duration)_ease-in-out_infinite] bg-[linear-gradient(90deg,transparent,currentColor,transparent)] motion-reduce:animate-none",
  pulse:
    "absolute inset-0 animate-[markas-gb-pulse_var(--markas-gb-duration)_ease-in-out_infinite] bg-[conic-gradient(from_180deg,currentColor,transparent_30%,currentColor_50%,transparent_80%,currentColor)] motion-reduce:animate-none",
};
const radii = {
  lg: { outer: "rounded-lg", inner: "rounded-[7px]" },
  xl: { outer: "rounded-xl", inner: "rounded-[11px]" },
  full: { outer: "rounded-full", inner: "rounded-full" },
};
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const speeds = { slow: "8s", normal: "4s", fast: "2s" };
const keyframes =
  "@keyframes markas-gb-spin{to{rotate:360deg}}@keyframes markas-gb-shine{0%{translate:-100% 0}60%,100%{translate:400% 0}}@keyframes markas-gb-pulse{50%{opacity:.2}}";
const cx = (...c: (string | false | null | undefined)[]) =>
  c.filter(Boolean).join(" ");

export type GradientBorderProps = ComponentProps<"div"> & {
  variant?: keyof typeof variants;
  color?: keyof typeof colors;
  speed?: keyof typeof speeds;
  radius?: keyof typeof radii;
  glow?: boolean;
};

export function GradientBorder({
  variant = "spin",
  color = "primary",
  speed = "normal",
  radius = "xl",
  glow = false,
  className,
  style,
  children,
  ...props
}: GradientBorderProps) {
  const vars = { "--markas-gb-duration": speeds[speed] } as CSSProperties;

  return (
    <div
      {...props}
      className={cx(base, radii[radius].outer, className)}
      style={{ ...vars, ...style }}
    >
      <style>{keyframes}</style>
      {glow && (
        <div aria-hidden="true" className={cx(layer, glowLayer, colors[color])}>
          <span className={variants[variant]} />
        </div>
      )}
      <div aria-hidden="true" className={cx(layer, colors[color])}>
        <span className={variants[variant]} />
      </div>
      <div className={cx(inner, radii[radius].inner)}>{children}</div>
    </div>
  );
}
```

```tsx
import { GradientBorder } from "@/components/markas/GradientBorder";

<GradientBorder variant="spin" glow className="max-w-80">
  <div className="grid gap-3 p-6">
    <h3 className="text-lg font-semibold text-ink">Pro workspace</h3>
    <Button>Upgrade now</Button>
  </div>
</GradientBorder>;
```

### Vue

Save at `src/components/markas/GradientBorder.vue`. No extra dependencies.

```vue
<script setup lang="ts">
import { computed } from "vue";

const base = "relative isolate bg-line p-px";
const layer =
  "pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] [container-type:size]";
const glowLayer = "-z-10 opacity-50 blur-lg";
const inner = "relative h-full bg-surface";
const variants = {
  spin: "absolute top-1/2 left-1/2 size-[calc(100cqw+100cqh)] -translate-x-1/2 -translate-y-1/2 animate-[markas-gb-spin_var(--markas-gb-duration)_linear_infinite] bg-[conic-gradient(transparent_0deg,currentColor_60deg,transparent_120deg,transparent_180deg,currentColor_240deg,transparent_300deg)] motion-reduce:animate-none",
  shine:
    "absolute inset-y-0 left-0 w-1/3 translate-x-full -skew-x-12 animate-[markas-gb-shine_var(--markas-gb-duration)_ease-in-out_infinite] bg-[linear-gradient(90deg,transparent,currentColor,transparent)] motion-reduce:animate-none",
  pulse:
    "absolute inset-0 animate-[markas-gb-pulse_var(--markas-gb-duration)_ease-in-out_infinite] bg-[conic-gradient(from_180deg,currentColor,transparent_30%,currentColor_50%,transparent_80%,currentColor)] motion-reduce:animate-none",
};
const radii = {
  lg: { outer: "rounded-lg", inner: "rounded-[7px]" },
  xl: { outer: "rounded-xl", inner: "rounded-[11px]" },
  full: { outer: "rounded-full", inner: "rounded-full" },
};
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const speeds = { slow: "8s", normal: "4s", fast: "2s" };
const keyframes =
  "@keyframes markas-gb-spin{to{rotate:360deg}}@keyframes markas-gb-shine{0%{translate:-100% 0}60%,100%{translate:400% 0}}@keyframes markas-gb-pulse{50%{opacity:.2}}";

const props = withDefaults(
  defineProps<{
    variant?: keyof typeof variants;
    color?: keyof typeof colors;
    speed?: keyof typeof speeds;
    radius?: keyof typeof radii;
    glow?: boolean;
  }>(),
  {
    variant: "spin",
    color: "primary",
    speed: "normal",
    radius: "xl",
    glow: false,
  },
);

const vars = computed(() => ({ "--markas-gb-duration": speeds[props.speed] }));
</script>

<template>
  <div :class="[base, radii[props.radius].outer]" :style="vars">
    <component :is="'style'">{{ keyframes }}</component>
    <div
      v-if="props.glow"
      aria-hidden="true"
      :class="[layer, glowLayer, colors[props.color]]"
    >
      <span :class="variants[props.variant]" />
    </div>
    <div aria-hidden="true" :class="[layer, colors[props.color]]">
      <span :class="variants[props.variant]" />
    </div>
    <div :class="[inner, radii[props.radius].inner]"><slot /></div>
  </div>
</template>
```

```vue
<template>
  <GradientBorder variant="spin" glow class="max-w-80">
    <div class="grid gap-3 p-6">
      <h3 class="text-lg font-semibold text-ink">Pro workspace</h3>
      <Button>Upgrade now</Button>
    </div>
  </GradientBorder>
</template>
```

### Svelte

Save at `src/lib/components/markas/GradientBorder.svelte`. No extra dependencies.

```svelte
<script lang="ts">
  import type { Snippet } from "svelte";
  import type { HTMLAttributes } from "svelte/elements";

  const base = "relative isolate bg-line p-px";
  const layer =
    "pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] [container-type:size]";
  const glowLayer = "-z-10 opacity-50 blur-lg";
  const inner = "relative h-full bg-surface";
  const variants = {
    spin: "absolute top-1/2 left-1/2 size-[calc(100cqw+100cqh)] -translate-x-1/2 -translate-y-1/2 animate-[markas-gb-spin_var(--markas-gb-duration)_linear_infinite] bg-[conic-gradient(transparent_0deg,currentColor_60deg,transparent_120deg,transparent_180deg,currentColor_240deg,transparent_300deg)] motion-reduce:animate-none",
    shine:
      "absolute inset-y-0 left-0 w-1/3 translate-x-full -skew-x-12 animate-[markas-gb-shine_var(--markas-gb-duration)_ease-in-out_infinite] bg-[linear-gradient(90deg,transparent,currentColor,transparent)] motion-reduce:animate-none",
    pulse:
      "absolute inset-0 animate-[markas-gb-pulse_var(--markas-gb-duration)_ease-in-out_infinite] bg-[conic-gradient(from_180deg,currentColor,transparent_30%,currentColor_50%,transparent_80%,currentColor)] motion-reduce:animate-none",
  };
  const radii = {
    lg: { outer: "rounded-lg", inner: "rounded-[7px]" },
    xl: { outer: "rounded-xl", inner: "rounded-[11px]" },
    full: { outer: "rounded-full", inner: "rounded-full" },
  };
  const colors = {
    muted: "text-muted",
    primary: "text-primary",
    success: "text-success",
    warning: "text-warning",
    danger: "text-danger",
  };
  const speeds = { slow: "8s", normal: "4s", fast: "2s" };
  const keyframes =
    "@keyframes markas-gb-spin{to{rotate:360deg}}@keyframes markas-gb-shine{0%{translate:-100% 0}60%,100%{translate:400% 0}}@keyframes markas-gb-pulse{50%{opacity:.2}}";

  type Props = HTMLAttributes<HTMLDivElement> & {
    variant?: keyof typeof variants;
    color?: keyof typeof colors;
    speed?: keyof typeof speeds;
    radius?: keyof typeof radii;
    glow?: boolean;
    children?: Snippet;
  };

  let {
    variant = "spin",
    color = "primary",
    speed = "normal",
    radius = "xl",
    glow = false,
    class: className,
    style,
    children,
    ...rest
  }: Props = $props();
</script>

<div
  {...rest}
  class={[base, radii[radius].outer, className]}
  style="--markas-gb-duration:{speeds[speed]};{style ?? ''}"
>
  {@html `<style>${keyframes}</style>`}
  {#if glow}
    <div aria-hidden="true" class={[layer, glowLayer, colors[color]]}>
      <span class={variants[variant]}></span>
    </div>
  {/if}
  <div aria-hidden="true" class={[layer, colors[color]]}>
    <span class={variants[variant]}></span>
  </div>
  <div class={[inner, radii[radius].inner]}>{@render children?.()}</div>
</div>
```

```svelte
<script lang="ts">
  import Button from "$lib/components/markas/Button.svelte";
  import GradientBorder from "$lib/components/markas/GradientBorder.svelte";
</script>

<GradientBorder variant="spin" glow class="max-w-80">
  <div class="grid gap-3 p-6">
    <h3 class="text-lg font-semibold text-ink">Pro workspace</h3>
    <Button>Upgrade now</Button>
  </div>
</GradientBorder>
```

### Astro

Save at `src/components/markas/GradientBorder.astro`. No extra dependencies.

```astro
---
import type { HTMLAttributes } from "astro/types";

const base = "relative isolate bg-line p-px";
const layer =
  "pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] [container-type:size]";
const glowLayer = "-z-10 opacity-50 blur-lg";
const inner = "relative h-full bg-surface";
const variants = {
  spin: "absolute top-1/2 left-1/2 size-[calc(100cqw+100cqh)] -translate-x-1/2 -translate-y-1/2 animate-[markas-gb-spin_var(--markas-gb-duration)_linear_infinite] bg-[conic-gradient(transparent_0deg,currentColor_60deg,transparent_120deg,transparent_180deg,currentColor_240deg,transparent_300deg)] motion-reduce:animate-none",
  shine:
    "absolute inset-y-0 left-0 w-1/3 translate-x-full -skew-x-12 animate-[markas-gb-shine_var(--markas-gb-duration)_ease-in-out_infinite] bg-[linear-gradient(90deg,transparent,currentColor,transparent)] motion-reduce:animate-none",
  pulse:
    "absolute inset-0 animate-[markas-gb-pulse_var(--markas-gb-duration)_ease-in-out_infinite] bg-[conic-gradient(from_180deg,currentColor,transparent_30%,currentColor_50%,transparent_80%,currentColor)] motion-reduce:animate-none",
};
const radii = {
  lg: { outer: "rounded-lg", inner: "rounded-[7px]" },
  xl: { outer: "rounded-xl", inner: "rounded-[11px]" },
  full: { outer: "rounded-full", inner: "rounded-full" },
};
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const speeds = { slow: "8s", normal: "4s", fast: "2s" };
const keyframes =
  "@keyframes markas-gb-spin{to{rotate:360deg}}@keyframes markas-gb-shine{0%{translate:-100% 0}60%,100%{translate:400% 0}}@keyframes markas-gb-pulse{50%{opacity:.2}}";

type Props = Omit<HTMLAttributes<"div">, "style"> & {
  variant?: keyof typeof variants;
  color?: keyof typeof colors;
  speed?: keyof typeof speeds;
  radius?: keyof typeof radii;
  glow?: boolean;
  style?: string;
};

const {
  variant = "spin",
  color = "primary",
  speed = "normal",
  radius = "xl",
  glow = false,
  class: className,
  style,
  ...rest
} = Astro.props;
---

<div
  {...rest}
  class:list={[base, radii[radius].outer, className]}
  style={`--markas-gb-duration:${speeds[speed]};${style ?? ""}`}
>
  <style is:inline set:html={keyframes} />
  {
    glow && (
      <div aria-hidden="true" class:list={[layer, glowLayer, colors[color]]}>
        <span class={variants[variant]} />
      </div>
    )
  }
  <div aria-hidden="true" class:list={[layer, colors[color]]}>
    <span class={variants[variant]}></span>
  </div>
  <div class:list={[inner, radii[radius].inner]}><slot /></div>
</div>
```

```astro
---
import Button from "@/components/markas/Button.astro";
import GradientBorder from "@/components/markas/GradientBorder.astro";
---

<GradientBorder variant="spin" glow class="max-w-80">
  <div class="grid gap-3 p-6">
    <h3 class="text-lg font-semibold text-ink">Pro workspace</h3>
    <Button>Upgrade now</Button>
  </div>
</GradientBorder>
```

No client-side JavaScript; the markup is rendered on the server.

### Angular

Save at `src/app/markas/gradient-border.component.ts`. No extra dependencies.

```ts
import {
  booleanAttribute,
  ChangeDetectionStrategy,
  Component,
  computed,
  input,
  ViewEncapsulation,
} from "@angular/core";

const base = "relative isolate bg-line p-px";
const layer =
  "pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit] [container-type:size]";
const glowLayer = "-z-10 opacity-50 blur-lg";
const inner = "relative h-full bg-surface";
const variants = {
  spin: "absolute top-1/2 left-1/2 size-[calc(100cqw+100cqh)] -translate-x-1/2 -translate-y-1/2 animate-[markas-gb-spin_var(--markas-gb-duration)_linear_infinite] bg-[conic-gradient(transparent_0deg,currentColor_60deg,transparent_120deg,transparent_180deg,currentColor_240deg,transparent_300deg)] motion-reduce:animate-none",
  shine:
    "absolute inset-y-0 left-0 w-1/3 translate-x-full -skew-x-12 animate-[markas-gb-shine_var(--markas-gb-duration)_ease-in-out_infinite] bg-[linear-gradient(90deg,transparent,currentColor,transparent)] motion-reduce:animate-none",
  pulse:
    "absolute inset-0 animate-[markas-gb-pulse_var(--markas-gb-duration)_ease-in-out_infinite] bg-[conic-gradient(from_180deg,currentColor,transparent_30%,currentColor_50%,transparent_80%,currentColor)] motion-reduce:animate-none",
};
const radii = {
  lg: { outer: "rounded-lg", inner: "rounded-[7px]" },
  xl: { outer: "rounded-xl", inner: "rounded-[11px]" },
  full: { outer: "rounded-full", inner: "rounded-full" },
};
const colors = {
  muted: "text-muted",
  primary: "text-primary",
  success: "text-success",
  warning: "text-warning",
  danger: "text-danger",
};
const speeds = { slow: "8s", normal: "4s", fast: "2s" };
const keyframes =
  "@keyframes markas-gb-spin{to{rotate:360deg}}@keyframes markas-gb-shine{0%{translate:-100% 0}60%,100%{translate:400% 0}}@keyframes markas-gb-pulse{50%{opacity:.2}}";

export type GradientBorderVariant = keyof typeof variants;
export type GradientBorderColor = keyof typeof colors;
export type GradientBorderSpeed = keyof typeof speeds;
export type GradientBorderRadius = keyof typeof radii;

/**
 * Attribute selector on a native div: the user's class, style, and attributes stay on the
 * root. The keyframes are a global style, so encapsulation is off.
 */
@Component({
  selector: "div[markas-gradient-border]",
  changeDetection: ChangeDetectionStrategy.OnPush,
  encapsulation: ViewEncapsulation.None,
  styles: [keyframes],
  host: {
    "[class]": "classes()",
    "[style.--markas-gb-duration]": "duration()",
  },
  template: `
    @if (glow()) {
      <div aria-hidden="true" [class]="glowClasses()">
        <span [class]="sweep()"></span>
      </div>
    }
    <div aria-hidden="true" [class]="layerClasses()">
      <span [class]="sweep()"></span>
    </div>
    <div [class]="innerClasses()"><ng-content /></div>
  `,
})
export class GradientBorder {
  readonly variant = input<GradientBorderVariant>("spin");
  readonly color = input<GradientBorderColor>("primary");
  readonly speed = input<GradientBorderSpeed>("normal");
  readonly radius = input<GradientBorderRadius>("xl");
  readonly glow = input(false, { transform: booleanAttribute });

  protected readonly classes = computed(
    () => `${base} ${radii[this.radius()].outer}`,
  );
  protected readonly duration = computed(() => speeds[this.speed()]);
  protected readonly sweep = computed(() => variants[this.variant()]);
  protected readonly layerClasses = computed(
    () => `${layer} ${colors[this.color()]}`,
  );
  protected readonly glowClasses = computed(
    () => `${layer} ${glowLayer} ${colors[this.color()]}`,
  );
  protected readonly innerClasses = computed(
    () => `${inner} ${radii[this.radius()].inner}`,
  );
}
```

```ts
import { Component } from "@angular/core";
import { Button } from "./markas/button.component";
import { GradientBorder } from "./markas/gradient-border.component";

@Component({
  selector: "app-hero",
  imports: [Button, GradientBorder],
  template: `
    <div markas-gradient-border variant="spin" glow class="max-w-80">
      <div class="grid gap-3 p-6">
        <h3 class="text-lg font-semibold text-ink">Pro workspace</h3>
        <button markas-button>Upgrade now</button>
      </div>
    </div>
  `,
})
export class Hero {}
```

The component is an attribute on a div, so class, style, and other attributes stay on the root element.

## Props

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `variant` | `spin \| shine \| pulse` | spin | spin rotates a conic gradient around the edge, shine sweeps a glint across, pulse breathes the whole border. |
| `color` | `muted \| primary \| success \| warning \| danger` | primary | Token color of the gradient. |
| `speed` | `slow \| normal \| fast` | normal | Length of one cycle: 8s, 4s, or 2s. |
| `radius` | `lg \| xl \| full` | xl | Corner radius of the border and the inner surface. |
| `glow` | `boolean` | false | Adds a soft blurred copy of the gradient behind the border. |
| `children / slot` | `slot / ReactNode / snippet` | - | Content inside the border, on a bg-surface panel. |

## Accessibility

- The gradient layers are aria-hidden and ignore pointer events.
- With reduced motion, the gradient stays still in a fixed position.
- Focus styles of the content inside are not covered by the border.

## Notes

- The border is 1px. Put padding on the content inside; the inner panel uses `bg-surface`.
- For a pill button use `radius="full"` with `inline-block` on the component and `rounded-full` on the button.
- `spin` uses container query units, supported by every current browser.
- The component has no built-in text, so there are no label props to translate.
