Tilt

A card that tilts in 3D toward the pointer and returns flat.

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

Libraries

PrequelUI

Motion

Spring + short tween

Reduced motion

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

Installation

Installing for React·components/prequelui/effects/tilt.tsx

Add the component

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

import * as React from "react";
import {
  motion,
  useMotionValue,
  useSpring,
  type HTMLMotionProps,
  type SpringOptions,
} from "motion/react";
import { cn } from "@/lib/utils";
import { useReduceMotion, useTempoTransition } from "../motion";

export type TiltProps = HTMLMotionProps<"div"> & {
  maxTilt?: number;
  perspective?: number;
  transition?: SpringOptions;
};

const defaultSpring: SpringOptions = {
  stiffness: 300,
  damping: 25,
  mass: 0.5,
};

export function Tilt({
  maxTilt = 10,
  perspective = 800,
  transition,
  className,
  style,
  onPointerMove,
  onPointerLeave,
  ...props
}: TiltProps) {
  const rawX = useMotionValue(0);
  const rawY = useMotionValue(0);
  const tempoSpring = useTempoTransition(transition ?? defaultSpring) as SpringOptions;
  const rotateX = useSpring(rawX, tempoSpring);
  const rotateY = useSpring(rawY, tempoSpring);
  const reduce = useReduceMotion();

  const handleMove = (event: React.PointerEvent<HTMLDivElement>) => {
    onPointerMove?.(event);
    if (reduce) return;
    const rect = event.currentTarget.getBoundingClientRect();
    const px = rect.width ? (event.clientX - rect.left) / rect.width : 0.5;
    const py = rect.height ? (event.clientY - rect.top) / rect.height : 0.5;
    rawY.set((px * 2 - 1) * maxTilt);
    rawX.set(-(py * 2 - 1) * maxTilt);
  };

  const handleLeave = (event: React.PointerEvent<HTMLDivElement>) => {
    onPointerLeave?.(event);
    rawX.set(0);
    rawY.set(0);
  };

  React.useEffect(() => {
    if (!reduce) return;
    rawX.jump(0);
    rawY.jump(0);
    rotateX.jump(0);
    rotateY.jump(0);
  }, [rawX, rawY, reduce, rotateX, rotateY]);

  return (
    <motion.div
      data-slot="tilt"
      className={cn("will-change-transform", className)}
      style={{
        rotateX,
        rotateY,
        transformPerspective: perspective,
        transformStyle: "preserve-3d",
        ...style,
      }}
      onPointerMove={handleMove}
      onPointerLeave={handleLeave}
      {...props}
    >
      {props.children}
    </motion.div>
  );
}

Install

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

tilt.tsx
import { Tilt } from "@/components/prequelui/effects/tilt";

export default function Demo() {
  return (
    <Tilt maxTilt={10} perspective={800} className="size-56 rounded-2xl border p-5">
      Look at me.
    </Tilt>
  );
}
import { Tilt } from "@/components/prequelui/tilt";

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

Animation

The card maps the pointer position to a pair of rotations. The raw values are passed through the same spring, so the tilt eases in, retargets while the pointer moves and returns flat when it leaves. Perspective is set on the transform itself so the card keeps its own layout.

  • Spring: stiffness 300, damping 25, mass 0.5.
  • Maximum tilt is 10° by default and perspective is 800.
  • The pointer is read from the element rect and normalised to −1…1.
  • Reduced motion settles both rotations at zero.
spring 300 / 25max 10°perspective 800pointer normalised
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.

Tilt

PropTypeDefault
maxTiltnumber10
perspectivenumber800
transitionSpringOptions300 / 25 / 0.5
classNamestring—

Next component

Zoom

An entrance that scales from half size with a spring.