Crisp letters lit from behind by a soft, slowly flowing glow of colour, the way a new AI feature or a launch headline glows.
A headline that resolves like an image loading: it arrives as a few big blocks of colour, and each step halves the pixels until the letters snap sharp.
Now loading.
Customize
Usage
import { PixelReveal } from "@/components/motionkit/pixel-reveal";
<PixelReveal as="h1" text="Now loading." className="text-7xl font-semibold" />Motion
The exact curves this component runs, plotted with Motion's own maths.
Pixels resolve
Scrolls into view
Tech and gaming launches, retro and creative studio sites, loading and coming-soon pages, and headlines that should feel like they're arriving.
Once fonts have loaded and the heading scrolls into view, the text is drawn into a canvas in its real font, size and colour. Each step draws that canvas much smaller and scales it back up with image smoothing turned off, which shows it as blocks; the block size shrinks by a constant factor each step until it reaches single pixels. Then the canvas hides and the real text, which was in the page all along, takes over, so it stays selectable and readable by screen readers.
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/pixel-reveal.jsonnpm install motionSave as components/motionkit/pixel-reveal.tsx.
"use client";
import { useEffect, useRef, useState, type ElementType } from "react";
import { useInView, useReducedMotion } from "motion/react";
type PixelRevealProps = {
text: string;
/** Seconds from coarsest pixels to sharp. */
duration?: number;
/** Size of the first, largest pixels, in px. */
block?: number;
/** Play again each time it comes back into view. */
repeat?: boolean;
/** The element to render, e.g. "h1". */
as?: ElementType;
className?: string;
};
/**
* A headline that resolves like an image loading over a slow connection: it arrives as a few large blocks of
* colour, and each step halves the pixels until the letters snap sharp. The text itself is real and selectable.
*/
export function PixelReveal({ text, duration = 1.4, block = 28, repeat = false, as: Tag = "span", className = "" }: PixelRevealProps) {
const reduceMotion = useReducedMotion();
const ref = useRef<HTMLElement>(null);
const canvasRef = useRef<HTMLCanvasElement>(null);
const inView = useInView(ref, { once: !repeat, amount: 0.6 });
const [done, setDone] = useState(false);
useEffect(() => {
const element = ref.current;
const canvas = canvasRef.current;
if (!element || !canvas || reduceMotion) return;
if (!inView) return;
let cancelled = false;
let timer = 0;
(async () => {
// the canvas must draw in the same font as the text, so wait for web fonts first
await document.fonts?.ready;
if (cancelled) return;
const style = getComputedStyle(element);
const rect = element.getBoundingClientRect();
const ratio = Math.min(window.devicePixelRatio || 1, 2);
const width = Math.ceil(rect.width);
const height = Math.ceil(rect.height);
canvas.width = width * ratio;
canvas.height = height * ratio;
canvas.style.width = `${width}px`;
canvas.style.height = `${height}px`;
// the sharp text, drawn once
const source = document.createElement("canvas");
source.width = canvas.width;
source.height = canvas.height;
const s = source.getContext("2d")!;
s.scale(ratio, ratio);
s.font = `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
s.fillStyle = style.color;
s.textBaseline = "middle";
// the element shrinks to fit the text, so drawing from the left edge lines up whatever the alignment
s.textAlign = "left";
if ("letterSpacing" in s) (s as CanvasRenderingContext2D & { letterSpacing: string }).letterSpacing = style.letterSpacing === "normal" ? "0px" : style.letterSpacing;
s.fillText(text, 0, height / 2);
// each step draws the text tiny, then scales it back up without smoothing, so it shows as blocks
const c = canvas.getContext("2d")!;
const small = document.createElement("canvas");
const steps: number[] = [];
for (let size = block; size > 1.5; size /= 1.7) steps.push(size);
steps.push(1);
const each = (duration * 1000) / steps.length;
const draw = (index: number) => {
if (cancelled) return;
const size = steps[index] * ratio;
small.width = Math.max(1, Math.round(canvas.width / size));
small.height = Math.max(1, Math.round(canvas.height / size));
const sc = small.getContext("2d")!;
sc.imageSmoothingEnabled = true;
sc.drawImage(source, 0, 0, small.width, small.height);
c.clearRect(0, 0, canvas.width, canvas.height);
c.imageSmoothingEnabled = false;
c.globalAlpha = 0.35 + (index / steps.length) * 0.65;
c.drawImage(small, 0, 0, canvas.width, canvas.height);
if (index < steps.length - 1) timer = window.setTimeout(() => draw(index + 1), each);
else timer = window.setTimeout(() => setDone(true), each);
};
setDone(false);
draw(0);
})();
return () => {
cancelled = true;
window.clearTimeout(timer);
};
}, [inView, reduceMotion, text, duration, block, repeat]);
const settled = done || reduceMotion;
return (
<Tag ref={ref} className={`relative inline-block whitespace-nowrap ${className}`}>
<span style={{ opacity: settled ? 1 : 0 }}>{text}</span>
{/* kept mounted, so a repeat play has a canvas to draw on */}
<canvas ref={canvasRef} aria-hidden className="pointer-events-none absolute left-0 top-0" style={{ visibility: settled ? "hidden" : "visible" }} />
</Tag>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
| text | string | — | The headline, on one line. |
| duration | number | 1.4 | Seconds from coarsest pixels to sharp. |
| block | number | 28 | Size of the first, largest pixels, in px. |
| repeat | boolean | false | Play again each time it comes back into view. |
| as | ElementType | "span" | Element to render, e.g. h1. |
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/pixel-reveal.json in any project with a components.json. It saves the file to components/motionkit and installs its dependencies.
With reduced motion on, the text simply appears, sharp.
Crisp letters lit from behind by a soft, slowly flowing glow of colour, the way a new AI feature or a launch headline glows.
A headline cut into bands like a sliced print: hover and the bands slide apart in alternate directions, revealing the word in a second colour through the cut.
Lettering made of glass: see-through letters with a bright top edge, a fine rim and a soft glow, and a highlight that glides across with the pointer.