Thin grid lines with streaks of light falling down them at scattered times.
Op-art interference: two fine patterns overlap and one drifts, so large ghostly bands ripple through them that neither layer contains.
Customize
Usage
import { MoireField } from "@/components/motionkit/moire-field";
<MoireField
className="h-[32rem]"
>
<h1>Your hero</h1>
</MoireField>Motion
The exact curves this component runs, plotted with Motion's own maths.
Layer drifts
Runs on its own
Leans to pointer
Pointer moves
Design studios, architecture and art sites, music and event posters, and minimal heroes that want movement without imagery.
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.
Works in the App Router as is. Requires Tailwind CSS v4.
One command adds the file and installs its dependencies. Needs a components.json (run npx shadcn@latest init once if you don't have one).
npx shadcn@latest add https://www.motionkitui.com/r/moire-field.jsonnpm install motionSave as components/motionkit/moire-field.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>
);
}
| 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. |
How we audit: the WCAG 2.2 animation checklist and respecting reduced motion in React.
Yes. The file starts with "use client", so you can import it straight into a Server Component page or layout. It works in Vite as is, and in Astro as a React island.
Only the motion package, beside React and Tailwind CSS v4. There is no MotionKit package and no Tailwind config to add.
Yes. Run npx shadcn@latest add https://www.motionkitui.com/r/moire-field.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
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.
Thin grid lines with streaks of light falling down them at scattered times.
Dozens of fine lines flowing like a length of silk in two colours, parting gently around the pointer.
A ribbon woven from dozens of fine threads of spectral light, gathering into a bright seam where it turns side-on and fanning into a veil of colour.
Interference