# Moiré Field

> Op-art interference: two fine patterns overlap and one drifts, so large ghostly bands ripple through them that neither layer contains.

Category: Backgrounds · Free · Updated 2026-11-10 · Live demo: https://www.motionkitui.com/components/moire-field

## When to use it

Design studios, architecture and art sites, music and event posters, and minimal heroes that want movement without imagery.

## How it works

Two layers of repeating gradients, rings or lines, sit on top of each other. One layer drifts in a slow orbit (rings) or swings a few degrees back and forth (lines), and leans towards the pointer through a spring. Where the two sets of lines fall in and out of step, large curved bands appear that neither layer contains: that's moiré. A radial mask fades it out towards the edges, and the moving layer is only ever transformed, so it costs almost nothing to animate.

## Installation

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

Or copy `components/motionkit/moire-field.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 |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | Your content, layered above the pattern. |
| `pattern` | `"rings" \| "lines"` | `"rings"` | Rings ripple from shifting centres; lines fan into bands as one set turns. |
| `colors` | `[string, string]` | `periwinkle, teal` | Colours of the two layers. |
| `background` | `string` | `"#0C1010"` | Colour underneath. |
| `spacing` | `number` | `7` | Distance between lines, in px. |
| `thickness` | `number` | `1.2` | Line thickness, in px. |
| `duration` | `number` | `22` | Seconds for one drift of the moving layer. |
| `intensity` | `number` | `0.4` | How strongly the pattern shows, 0 to 1. |
| `interactive` | `boolean` | `true` | Let the moving layer lean towards the pointer. |

## Accessibility

- **Keyboard: Not applicable.** A decorative background.
- **Screen readers: Pass.** Every layer is hidden; only your content is read.
- **Reduced motion: Pass.** With reduced motion on, the patterns stop drifting and no longer follow the pointer. Moiré can still shimmer as the page scrolls, so keep the intensity low behind long reading.
- **Colour contrast: Partial.** Ivory text measures 17:1 between the lines but 3.4:1 where both layers cross at the default intensity, enough for large headings. For smaller text, lower the intensity or set it on a panel.

## Source

```tsx
"use client";

import { useRef, type PointerEvent, type ReactNode } from "react";
import { motion, useMotionValue, useReducedMotion, useSpring } from "motion/react";

type MoireFieldProps = {
  children?: ReactNode;
  /** Rings ripple outward from shifting centres; lines fan into curved bands as one set turns. */
  pattern?: "rings" | "lines";
  /** Colours of the two overlapping layers. */
  colors?: [string, string];
  background?: string;
  /** Distance between lines, in pixels. Finer lines make denser interference. */
  spacing?: number;
  /** Line thickness, in pixels. */
  thickness?: number;
  /** Seconds for one slow drift of the moving layer. */
  duration?: number;
  /** 0 to 1. How strongly the pattern shows. */
  intensity?: number;
  /** Let the moving layer lean toward the pointer. */
  interactive?: boolean;
  className?: string;
};

/**
 * Op-art interference: two fine patterns laid over each other, one drifting, so large ghostly bands ripple through
 * them that neither layer contains. Pure CSS gradients moved on the GPU, fading out towards the edges.
 */
export function MoireField({
  children,
  pattern = "rings",
  colors = ["#B9C7FF", "#5FAEB4"],
  background = "#0C1010",
  spacing = 7,
  thickness = 1.2,
  duration = 22,
  intensity = 0.4,
  interactive = true,
  className = "",
}: MoireFieldProps) {
  const ref = useRef<HTMLDivElement>(null);
  const reduceMotion = useReducedMotion();
  const pointerX = useMotionValue(0);
  const pointerY = useMotionValue(0);
  const x = useSpring(pointerX, { stiffness: 40, damping: 16 });
  const y = useSpring(pointerY, { stiffness: 40, damping: 16 });

  const lines = (color: string) => {
    const stops = `${color} 0, ${color} ${thickness}px, transparent ${thickness + 0.6}px, transparent ${spacing}px`;
    return pattern === "rings" ? `repeating-radial-gradient(circle at 50% 50%, ${stops})` : `repeating-linear-gradient(90deg, ${stops})`;
  };

  function move(event: PointerEvent) {
    if (!interactive || reduceMotion || event.pointerType === "touch") return;
    const rect = ref.current!.getBoundingClientRect();
    const reach = spacing * 6;
    pointerX.set(((event.clientX - rect.left) / rect.width - 0.5) * reach * 2);
    pointerY.set(((event.clientY - rect.top) / rect.height - 0.5) * reach * 2);
  }

  function leave() {
    pointerX.set(0);
    pointerY.set(0);
  }

  return (
    <div ref={ref} data-moire="" onPointerMove={move} onPointerLeave={leave} className={`relative isolate overflow-hidden ${className}`} style={{ backgroundColor: background }}>
      <style>{`
@keyframes moire-orbit{0%{transform:translate(3%,0)}25%{transform:translate(0,3%)}50%{transform:translate(-3%,0)}75%{transform:translate(0,-3%)}100%{transform:translate(3%,0)}}
@keyframes moire-turn{0%,100%{transform:rotate(-7deg)}50%{transform:rotate(7deg)}}
@media (prefers-reduced-motion:reduce){[data-moire] [data-moire-layer]{animation:none!important}}
`}</style>
      <div
        aria-hidden
        className="pointer-events-none absolute inset-0 -z-10"
        style={{
          opacity: intensity,
          maskImage: "radial-gradient(ellipse at center, black 25%, transparent 75%)",
          WebkitMaskImage: "radial-gradient(ellipse at center, black 25%, transparent 75%)",
        }}
      >
        <div className="absolute -inset-1/2" style={{ backgroundImage: lines(colors[0]) }} />
        <motion.div className="absolute -inset-1/2 mix-blend-screen" style={{ x, y }}>
          <div
            data-moire-layer=""
            className="absolute inset-0"
            style={{
              backgroundImage: lines(colors[1]),
              animation: `${pattern === "rings" ? "moire-orbit" : "moire-turn"} ${duration}s ${pattern === "rings" ? "linear" : "ease-in-out"} infinite`,
              willChange: "transform",
            }}
          />
        </motion.div>
      </div>
      {children}
    </div>
  );
}
```
