Flickering grid
Also called animated grid pattern, LED grid, or flickering squares
A grid of tiny squares whose opacity flickers at random, like a field of LEDs, usually faded out toward the edges with a mask.
import { useEffect, useRef } from 'react';
import { useInView, useReducedMotion } from 'motion/react';
const SIZE = 4; // square size in px
const STEP = 8; // square plus gap
const MAX_OPACITY = 0.38;
const CHANGES_PER_SECOND = 0.6; // chances per square
export function FlickeringGrid() {
const ref = useRef<HTMLCanvasElement>(null);
const inView = useInView(ref);
const reduceMotion = useReducedMotion();
useEffect(() => {
const canvas = ref.current!;
const ctx = canvas.getContext('2d')!;
const { clientWidth: width, clientHeight: height } = canvas;
const dpr = window.devicePixelRatio || 1; // sharp on high-density screens
canvas.width = width * dpr;
canvas.height = height * dpr;
ctx.scale(dpr, dpr);
// text-emerald-500 on the canvas sets the square color.
ctx.fillStyle = getComputedStyle(canvas).color;
const columns = Math.ceil(width / STEP);
const rows = Math.ceil(height / STEP);
const cells = Float32Array.from(
{ length: columns * rows },
() => Math.random() * MAX_OPACITY
);
const draw = () => {
ctx.clearRect(0, 0, width, height);
cells.forEach((opacity, i) => {
ctx.globalAlpha = opacity;
const x = (i % columns) * STEP;
const y = Math.floor(i / columns) * STEP;
ctx.fillRect(x, y, SIZE, SIZE);
});
};
draw(); // the still frame for reduced motion
if (!inView || reduceMotion) return;
let frame = 0;
let last = performance.now();
const tick = (now: number) => {
// Each square has a small chance per frame to jump to a new opacity.
const chance = (CHANGES_PER_SECOND * (now - last)) / 1000;
last = now;
for (let i = 0; i < cells.length; i++) {
if (Math.random() < chance) cells[i] = Math.random() * MAX_OPACITY;
}
draw();
frame = requestAnimationFrame(tick);
};
frame = requestAnimationFrame(tick);
return () => cancelAnimationFrame(frame);
}, [inView, reduceMotion]);
return (
<canvas
ref={ref}
aria-hidden
className='pointer-events-none absolute inset-0 size-full text-emerald-500 [mask-image:radial-gradient(ellipse_at_center,black_25%,transparent_75%)]'
/>
);
}Put a flickering grid behind the status page headline: a full-size canvas of 4px squares with 4px gaps, each starting at a random opacity between 0 and 38%, with a 0.6 chance per second of jumping to a new random opacity. Color the squares with the green text color, scale the canvas for devicePixelRatio, fade it toward the edges with a radial mask, pause the loop while the section is off screen, and draw one still frame when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Flickering grid?
A flickering grid fills a section with small squares in even rows and columns, and every so often each square jumps to a new random opacity. The result is a quiet shimmer, like a wall of status lights or a screen of pixels. Status pages, AI products, and data-heavy heroes use it as a texture behind a headline.
With thousands of squares, draw it on a <canvas> instead of creating elements. Keep one opacity per square in an array, give each square a small chance per frame to pick a new value, and redraw. A radial mask-image fades the grid toward the edges so it melts into the page. A related pattern lights up a handful of larger grid cells at a time.
Keep opacities low, roughly 0 to 40%, so text on top stays readable, and keep the flicker gentle: fast, high-contrast blinking is uncomfortable for people sensitive to flashing. Scale the canvas for devicePixelRatio, stop the loop when the section is off screen, and draw a single still frame under prefers-reduced-motion.
Often confused with
- Grid background
- A grid background is a still or slowly drifting pattern of lines or dots. A flickering grid keeps changing the brightness of each square at random.
Related terms
All termsGrid background
A decorative background of thin grid lines, dots, stripes, or hexagons, often faded toward the edges, used behind hero sections and product shots.
Glyph matrix
A grid of characters or symbols that keep switching at random and fading in and out, used as a digital or ASCII-style texture.
Mask
A CSS technique that uses an image or gradient to set how visible each part of an element is, often used to fade edges softly.
Reduced motion
An operating system setting that asks apps to minimize movement, which websites detect with the prefers-reduced-motion media query.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.