Back to PrequelUIYou are on Cursor.

Cursor

A custom cursor and a trailing label with two different springs.

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

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

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

Installation

Installing for React·components/prequelui/cursor.tsx

Add the component

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/cursor.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
cursor.tsx
"use client";

import * as React from "react";
import {
  AnimatePresence,
  motion,
  useMotionValue,
  useSpring,
  useTransform,
} from "motion/react";
import { cn } from "@/lib/utils";
import { cursorEntry, cursorExit, cursorLabel, useReduceMotion } from "./motion";

export type CursorProps = React.ComponentProps<"div"> & {
  label?: React.ReactNode;
  dotSize?: number;
  labelGap?: number;
  hideNative?: boolean;
};

export function Cursor({
  label,
  dotSize = 12,
  labelGap = 14,
  hideNative = true,
  className,
  children,
  onPointerMove,
  onPointerEnter,
  onPointerLeave,
  ...props
}: CursorProps) {
  const ref = React.useRef<HTMLDivElement>(null);
  const reduce = useReduceMotion();
  const [inside, setInside] = React.useState(false);
  const x = useMotionValue(0);
  const y = useMotionValue(0);
  const labelX = useSpring(x, cursorLabel);
  const labelY = useSpring(y, cursorLabel);
  const dotX = useTransform(x, (value) => value - dotSize / 2);
  const dotY = useTransform(y, (value) => value - dotSize / 2);
  const tipX = useTransform(labelX, (value) => value + labelGap);
  const tipY = useTransform(labelY, (value) => value + labelGap - 8);

  return (
    <div
      ref={ref}
      data-slot="cursor"
      className={cn("relative", hideNative && "cursor-none", className)}
      onPointerMove={(event) => {
        onPointerMove?.(event);
        const rect = ref.current?.getBoundingClientRect();
        if (!rect) return;
        x.set(event.clientX - rect.left);
        y.set(event.clientY - rect.top);
      }}
      onPointerEnter={(event) => {
        onPointerEnter?.(event);
        setInside(true);
      }}
      onPointerLeave={(event) => {
        onPointerLeave?.(event);
        setInside(false);
      }}
      {...props}
    >
      {children}
      <AnimatePresence>
        {inside ? (
          <React.Fragment key="cursor">
            <motion.span
              aria-hidden="true"
              data-slot="cursor-dot"
              initial={{ scale: 0, opacity: 0 }}
              animate={{ scale: 1, opacity: 1 }}
              exit={{ scale: 0, opacity: 0 }}
              transition={reduce ? { duration: 0 } : cursorEntry}
              style={{ x: dotX, y: dotY, width: dotSize, height: dotSize }}
              className="pointer-events-none absolute left-0 top-0 z-50 rounded-full bg-foreground"
            />
            {label ? (
              <motion.span
                aria-hidden="true"
                data-slot="cursor-label"
                initial={{ scale: 0.8, opacity: 0 }}
                animate={{ scale: 1, opacity: 1 }}
                exit={{ scale: 0.8, opacity: 0 }}
                transition={reduce ? { duration: 0 } : cursorExit}
                style={{ x: tipX, y: tipY }}
                className="pointer-events-none absolute left-0 top-0 z-50 whitespace-nowrap rounded-full bg-foreground px-2 py-0.5 text-[13px] font-medium text-background"
              >
                {label}
              </motion.span>
            ) : null}
          </React.Fragment>
        ) : null}
      </AnimatePresence>
    </div>
  );
}

Install

npx shadcn@latest add https://prequeluianimate.terravidhal.me/r/cursor.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.

cursor.tsx
import { Cursor } from "@/components/prequelui/cursor";

export default function Demo() {
  return (
    <Cursor
      label="Vidhal"
      className="flex h-48 items-center justify-center rounded-xl border"
    >
      <span>Move your pointer here</span>
    </Cursor>
  );
}
import { Cursor } from "@/components/prequelui/cursor";

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

Animation

The point is glued to the pointer with no lag; the label trails behind on a softer spring. The two use different stiffness values on purpose, so the cursor feels precise while the label feels elastic.

  • Cursor entry: 550 / 30 with restSpeed 10.
  • Label follow: 500 / 50 with no bounce.
  • Touch pointers are ignored entirely.
  • Leaving the parent fades the cursor out without a jump.
spring 500 / 50pause off-screenpointer-awareinterruptible
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.

Cursor

PropTypeDefault
labelReactNode—
dotSizenumber12
labelGapnumber14
hideNativebooleantrue
childrenReactNode—

Next component

GitHub Stars

A repository star count that ticks up and bursts into particles.