Glyph matrix
Also called ASCII background, character grid animation, or random glyph texture
A grid of characters or symbols that keep switching at random and fading in and out, used as a digital or ASCII-style texture.
import { useEffect, useRef } from 'react';
import { useInView, useReducedMotion } from 'motion/react';
const GLYPHS = '0123456789ABCDEF';
const CELL = { width: 14, height: 18 }; // px, for 13px monospace text
const CHANGES_PER_SECOND = 1.2; // chances per cell
const pick = () => GLYPHS[Math.floor(Math.random() * GLYPHS.length)]!;
const dim = () => Math.random() ** 2 * 0.5; // mostly faint, a few brighter
export function GlyphMatrix() {
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;
canvas.width = width * dpr;
canvas.height = height * dpr;
ctx.scale(dpr, dpr);
ctx.font = '13px ui-monospace, monospace';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillStyle = getComputedStyle(canvas).color;
const columns = Math.ceil(width / CELL.width);
const count = columns * Math.ceil(height / CELL.height);
const cells = Array.from({ length: count }, () => {
const target = dim();
return { glyph: pick(), opacity: target, target };
});
const draw = () => {
ctx.clearRect(0, 0, width, height);
cells.forEach((cell, i) => {
ctx.globalAlpha = cell.opacity;
const x = ((i % columns) + 0.5) * CELL.width;
const y = (Math.floor(i / columns) + 0.5) * CELL.height;
ctx.fillText(cell.glyph, x, y);
});
};
draw(); // the still frame for reduced motion
if (!inView || reduceMotion) return;
let frame = 0;
let last = performance.now();
const tick = (now: number) => {
const seconds = (now - last) / 1000;
last = now;
for (const cell of cells) {
if (Math.random() < CHANGES_PER_SECOND * seconds) {
// Swap the glyph and dip, then fade up to the new brightness.
cell.glyph = pick();
cell.target = dim();
cell.opacity *= 0.25;
}
cell.opacity += (cell.target - cell.opacity) * Math.min(1, seconds * 7);
}
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-muted-foreground [mask-image:radial-gradient(ellipse_at_center,black_35%,transparent_80%)]'
/>
);
}Behind the "Secrets encrypted" card, add a glyph matrix: a full-size canvas grid of 13px monospace hex characters (0–9 and A–F) in cells about 14 by 18px. Give each cell a random glyph and an opacity between 0 and 50%, mostly dim, and light about 3% of cells in a bright green accent. Each cell has a 1.2 chance per second to pick a new glyph and target opacity, dipping first and easing toward the target so it fades in. Fade the edges with a radial mask, scale for devicePixelRatio, pause off screen, and draw a still frame when prefers-reduced-motion is set.
Paste into Layerwise or any AI coding tool.
What is Glyph matrix?
A glyph matrix fills an area with a fixed grid of monospace characters, such as hex digits, binary, or ASCII symbols, and keeps changing them. Every so often a cell picks a new glyph and brightness and fades toward it, so the surface shimmers like a terminal full of data. It sets a technical mood behind security features, AI products, and developer tools.
Draw it on a <canvas> with fillText, since thousands of DOM nodes changing many times a second would be slow. Store a glyph, a current opacity, and a target opacity for every cell, give each cell a small chance per frame to roll new values, and ease the opacity toward its target so each change fades in smoothly. A few cells lit in an accent color add depth.
Keep most glyphs dim and fade the edges with a mask so a card or headline on top stays readable. The characters are decoration: hide the canvas from screen readers with aria-hidden, pause the loop while it is off screen, and draw one still frame under prefers-reduced-motion.
Often confused with
- Text scramble
- A text scramble cycles random characters inside real words until they settle on the final text. A glyph matrix is a background texture whose characters never settle.
Related terms
All termsText scramble
A text animation where each character flickers through random letters and symbols before settling on the final word, like a code being cracked.
Flickering grid
A grid of tiny squares whose opacity flickers at random, like a field of LEDs, usually faded out toward the edges with a mask.
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.
Frame rate (FPS)
The number of frames a screen draws each second; around 60 fps, motion looks smooth, and at lower rates it starts to look choppy.
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.