# Photo Fan

> A little pile of instant photos that fans out like a hand of cards on hover, each print lifting clear as you point at it.

Category: Cards · Free · Updated 2026-11-09 · Live demo: https://www.motionkitui.com/components/photo-fan

## When to use it

About pages and personal sites, travel and wedding photography, team culture sections, and testimonials with a photo of each customer.

## How it works

The prints share one bottom-centre position and are rotated around a point below themselves, so changing the angle swings them out like cards held in a hand. Stacked, each has a small fixed tilt so the pile looks dropped on a table and matches on the server and in the browser. Fanned, the angles are spread evenly across the spread prop and nudged outwards. Pointing at a print raises it above the others with a lift, a slight scale and a gloss. Everything runs on springs, and touch gets a tap to open and a tap to lift.

## Installation

```bash
npx shadcn@latest add https://www.motionkitui.com/r/photo-fan.json
```

Or copy `components/motionkit/photo-fan.tsx` below. Requires react, motion and Tailwind CSS v4. Free for personal projects; commercial use needs MotionKit Plus (https://www.motionkitui.com/pricing).

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `photos` | `FanPhoto[]` |  | Each photo's src, alt and an optional handwritten-style caption. |
| `spread` | `number` | `46` | Total angle in degrees the fan opens across. |
| `width` | `number` | `132` | Width of each print in pixels. |
| `open` | `boolean` | `false` | Start fanned out instead of stacked. |

## Accessibility

- **Keyboard: Pass.** Every print is a tab stop with a visible focus ring; focusing one fans the pile and raises that print.
- **Screen readers: Pass.** A group that says how many photos it holds; each print is read by its caption and its image's alt text.
- **Reduced motion: Pass.** With reduced motion on, the fan opens and prints lift instantly instead of springing.
- **Colour contrast: Pass.** Captions measure 13.3:1 on the print's cream border.

## Source

```tsx
"use client";

import { useState } from "react";
import { motion, useReducedMotion } from "motion/react";

export type FanPhoto = { src: string; alt: string; caption?: string };

type PhotoFanProps = {
  photos: FanPhoto[];
  /** Total angle in degrees the photos spread across when fanned. */
  spread?: number;
  /** Width of each print in pixels. */
  width?: number;
  /** Start fanned out instead of stacked. */
  open?: boolean;
  className?: string;
};

// small, fixed tilts so the stack looks dropped on a table, the same on the server and in the browser
const resting = [-4, 3, -1.5, 5, -3, 2, -5, 1];

/**
 * A little pile of instant photos. Hover or focus and they fan out like a hand of cards; point at one and it lifts
 * clear of the others. On touch, a tap opens the fan and a second tap on a print raises it.
 */
export function PhotoFan({ photos, spread = 46, width = 132, open = false, className = "" }: PhotoFanProps) {
  const reduceMotion = useReducedMotion();
  const [hovered, setHovered] = useState(false);
  const [tapped, setTapped] = useState(open);
  const [lifted, setLifted] = useState<number | null>(null);
  const fanned = hovered || tapped || open;

  const count = photos.length;
  const middle = (count - 1) / 2;
  const height = Math.round(width * 1.22);
  const spring = reduceMotion ? { duration: 0 } : { type: "spring" as const, stiffness: 260, damping: 24 };

  return (
    <div
      role="group"
      aria-label={`${count} photos`}
      onPointerEnter={(event) => event.pointerType === "mouse" && setHovered(true)}
      onPointerLeave={() => {
        setHovered(false);
        setLifted(null);
      }}
      onFocus={() => setTapped(true)}
      onBlur={(event) => {
        if (!event.currentTarget.contains(event.relatedTarget)) {
          setTapped(open);
          setLifted(null);
        }
      }}
      onClick={() => setTapped(true)}
      className={`relative flex items-end justify-center ${className}`}
      style={{ width: width * (1.6 + count * 0.32), height: height * 1.45 }}
    >
      {photos.map((photo, index) => {
        const offset = index - middle;
        const angle = count > 1 ? (offset / middle) * (spread / 2) : 0;
        const isLifted = lifted === index;
        return (
          <motion.figure
            key={photo.src + index}
            tabIndex={0}
            aria-label={photo.caption ?? photo.alt}
            onPointerEnter={(event) => event.pointerType === "mouse" && setLifted(index)}
            onFocus={() => setLifted(index)}
            onClick={(event) => {
              if (!fanned) return;
              event.stopPropagation();
              setLifted(isLifted ? null : index);
            }}
            className="absolute bottom-4 m-0 cursor-pointer rounded-[3px] bg-[#F6F1E8] p-2 pb-0 shadow-[0_1px_2px_rgb(0_0_0/0.3),0_14px_30px_-8px_rgb(0_0_0/0.55)] outline-none focus-visible:ring-2 focus-visible:ring-[#5FAEB4] focus-visible:ring-offset-2 focus-visible:ring-offset-[#0C1010]"
            style={{ width, transformOrigin: "50% 140%", zIndex: isLifted ? count + 1 : index }}
            initial={false}
            animate={
              fanned
                ? { rotate: angle, x: offset * width * 0.2, y: isLifted ? -26 : Math.abs(offset) * 4, scale: isLifted ? 1.06 : 1 }
                : { rotate: resting[index % resting.length], x: offset * 3, y: 0, scale: 1 }
            }
            transition={spring}
          >
            {/* eslint-disable-next-line @next/next/no-img-element -- framework-agnostic: works outside Next.js too */}
            <img src={photo.src} alt={photo.alt} draggable={false} className="block w-full rounded-[1px] object-cover" style={{ height: height - 40 }} />
            <figcaption className="flex h-8 items-center justify-center truncate px-1 font-serif text-[13px] italic text-[#2A2622]">{photo.caption ?? ""}</figcaption>
            {/* a gloss that catches the light as a print is raised */}
            <motion.span
              aria-hidden
              className="pointer-events-none absolute inset-0 rounded-[3px] bg-[linear-gradient(135deg,rgb(255_255_255/0.35),transparent_45%)]"
              initial={false}
              animate={{ opacity: isLifted ? 1 : 0 }}
              transition={{ duration: reduceMotion ? 0 : 0.25 }}
            />
          </motion.figure>
        );
      })}
    </div>
  );
}
```
