Back to BackgroundsYou are on Gradient.

Gradient

A quiet animated gradient that gives the page depth.

Available inAvailable in React, Vue, Svelte, Solid, JavaScript· All five frameworks
PrequelUI

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

Fade in place
gradient.tsx
Play with the real component, then read the code it ships with.All components
01

Installation

Installing for React·components/prequelui/backgrounds/gradient.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/gradient.json
npmthe default on every machine

First component? Set up your project first

Frameworks

The live preview is React. Each tab below is the file that ships for that framework, with the same durations, springs and reduced-motion rule.

5 runtimes
gradient.tsx
"use client";

import * as React from "react";
import { motion } from "motion/react";
import { cn } from "@/lib/utils";
import { useBackgroundPlayback } from "./shared";

export type GradientBackgroundProps = React.ComponentProps<"div"> & {
  speed?: number;
  paused?: boolean;
  gradient?: string;
};

const DEFAULT_GRADIENT =
  "linear-gradient(120deg, #312e81 0%, #6d28d9 24%, #be185d 48%, #c2410c 72%, #0f766e 100%)";

export function GradientBackground({
  speed = 1,
  paused = false,
  gradient = DEFAULT_GRADIENT,
  className,
  children,
  ...props
}: GradientBackgroundProps) {
  const ref = React.useRef<HTMLDivElement>(null);
  const { playing: live, reduce } = useBackgroundPlayback(ref);
  const playing = live && !paused;
  const duration = 16 / Math.max(0.1, speed);

  return (
    <div
      ref={ref}
      data-slot="gradient-background"
      className={cn("relative size-full overflow-hidden bg-[#0a0910]", className)}
      {...props}
    >
      <motion.div
        aria-hidden="true"
        animate={
          playing
            ? { backgroundPosition: ["0% 50%", "100% 50%", "0% 50%"] }
            : { backgroundPosition: "0% 50%" }
        }
        transition={
          playing
            ? { duration, ease: "easeInOut", repeat: Infinity }
            : { duration: 0 }
        }
        className="absolute -inset-[35%] opacity-90 blur-[10px]"
        style={{
          backgroundImage: gradient,
          backgroundSize: "400% 400%",
          backgroundPosition: reduce ? "35% 50%" : undefined,
          willChange: "background-position",
        }}
      />
      <motion.div
        aria-hidden="true"
        animate={
          playing
            ? { x: ["-12%", "14%", "-12%"], y: ["-8%", "10%", "-8%"], scale: [1, 1.25, 1] }
            : { x: "-12%", y: "-8%" }
        }
        transition={
          playing
            ? { duration: duration * 1.6, ease: "easeInOut", repeat: Infinity }
            : { duration: 0 }
        }
        className="absolute left-[8%] top-[4%] size-[70%] rounded-full opacity-70 blur-[60px]"
        style={{
          background: "radial-gradient(circle, rgba(45,212,191,0.75), transparent 68%)",
          willChange: "transform",
        }}
      />
      <motion.div
        aria-hidden="true"
        animate={
          playing
            ? { x: ["10%", "-16%", "10%"], y: ["12%", "-10%", "12%"], scale: [1.1, 0.9, 1.1] }
            : { x: "10%", y: "12%" }
        }
        transition={
          playing
            ? { duration: duration * 2.1, ease: "easeInOut", repeat: Infinity }
            : { duration: 0 }
        }
        className="absolute bottom-[2%] right-[2%] size-[74%] rounded-full opacity-70 blur-[70px]"
        style={{
          background: "radial-gradient(circle, rgba(249,115,22,0.72), transparent 66%)",
          willChange: "transform",
        }}
      />
      <div
        aria-hidden="true"
        className="pointer-events-none absolute inset-0 bg-[radial-gradient(ellipse_at_center,transparent_10%,rgba(5,4,10,0.6))]"
      />
      {children}
    </div>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/gradient.json
npmthe default on every machine

Dependencies

motion lucide-react

The registry keeps the component source, its motion tokens and the reduced-motion branch together, so the install never pulls a different animation from the preview.

02

Usage

Import the component and compose it exactly like the primitive it wraps. Motion is enabled by default; the tempo prop scales every duration and softens every spring.

gradient.tsx
import { GradientBackground } from "@/components/prequelui/backgrounds/gradient";

export default function Demo() {
  return (
    <div className="relative h-96 overflow-hidden rounded-xl">
      <GradientBackground />
    </div>
  );
}
import { Gradient } from "@/components/prequelui/gradient";

export function Variant() {
  return (
    <Gradient tempo={1.2}>
      …
    </Gradient>
  );
}
03

Animation

An oversized gradient slides behind the content and returns. The loop is slow enough to read as light rather than motion, and a counter-rotating conic sheen keeps the surface from looking flat.

  • Background-size is 400%; the position travels 0% → 100% → 0% in 16 s.
  • The conic sheen turns once every four loops at a constant rate.
  • The gradient is darker by design, so foreground text stays readable.
  • Reduced motion freezes the position at an off-centre frame.
400% gradient16 s loopconic sheenfrozen still
04

API Reference

Each part accepts the usual HTML props in addition to the motion props below. No accessibility prop is hidden behind the animation layer.

GradientBackground

PropTypeDefault
gradientstringviolet → rose → amber → teal
speednumber1
pausedbooleanfalse
classNamestring—

Next component

Gravity Stars

Stars pulled and pushed by an interactive gravity well.