Tech Grid
An animated tech grid background for React and Tailwind CSS: a quiet blueprint grid with a faint scan line sweeping past, or a retro perspective floor that scrolls slowly toward the viewer. Built with Motion and pure CSS, no canvas.
- Background
- Blueprint grid
- Perspective
- Pauses off-screen
- Reduced-motion safe
Infrastructure as code
Describe your stack in one file and preview every change.
import { Button } from "@/components/ui/button";
import { TechGrid } from "@/components/dusk/techy/tech-grid";
export default function TechGridDemo() {
return (
<div className="relative flex h-80 w-full items-center justify-center overflow-hidden rounded-xl border border-white/10 bg-background">
<TechGrid />
<div className="relative px-6 text-center">
<h3 className="text-3xl font-semibold tracking-tight text-white">Infrastructure as code</h3>
<p className="mt-2 text-sm leading-relaxed text-white/60">Describe your stack in one file and preview every change.</p>
<Button className="mt-4" size="sm" variant="outline">
Read the docs
</Button>
</div>
</div>
);
}Installation
$ npx shadcn@latest add https://duskui.com/r/tech-grid.json1. Install the dependencies.
npm install motion2. Copy the source into
components/dusk/techy/tech-grid.tsx.tech-grid.tsx "use client"; import * as React from "react"; import { animate, useReducedMotion, type AnimationPlaybackControls } from "motion/react"; import { cn } from "@/lib/utils"; export interface TechGridProps extends React.ComponentProps<"div"> { /** `flat` is a blueprint grid; `perspective` is a receding floor that scrolls toward you. */ variant?: "flat" | "perspective"; /** Any CSS color for the lines. Defaults to white, mixed down to a faint tint. */ color?: string; /** Size of one grid cell in px. */ cellSize?: number; /** Speed multiplier for the floor and the scan line. */ speed?: number; /** Sweep a faint scan line across the grid. */ scanLine?: boolean; /** Fade the grid out toward the edges. */ fade?: boolean; } const mix = (color: string, amount: number) => `color-mix(in oklab, ${color} ${amount}%, transparent)`; const lines = (color: string) => `linear-gradient(to right, ${color} 1px, transparent 1px), linear-gradient(to bottom, ${color} 1px, transparent 1px)`; /** * An animated tech grid background. The flat variant is a quiet blueprint * grid with a faint scan line sweeping down; the perspective variant is a * retro floor that scrolls toward the viewer. Fills its nearest positioned parent. * * The background never takes pointer events, so content on top stays fully * interactive. Animations pause off-screen and in hidden tabs, and stop for * reduced motion. */ export function TechGrid({ variant = "flat", color = "rgb(255 255 255)", cellSize = 40, speed = 1, scanLine = true, fade = true, className, style, ...props }: TechGridProps) { const reduceMotion = useReducedMotion(); const rootRef = React.useRef<HTMLDivElement>(null); const floorRef = React.useRef<HTMLDivElement>(null); const scanRef = React.useRef<HTMLDivElement>(null); const cell = Math.max(8, cellSize); React.useEffect(() => { const root = rootRef.current; if (reduceMotion || !root) return; const rate = Math.max(speed, 0.05); const controls: AnimationPlaybackControls[] = []; if (variant === "perspective" && floorRef.current) { controls.push( animate(floorRef.current, { y: [0, cell] }, { duration: 2 / rate, ease: "linear", repeat: Infinity }) ); } if (scanLine && scanRef.current) { controls.push( animate( scanRef.current, { y: ["-100%", "4%"] }, { duration: (variant === "perspective" ? 3.5 : 5) / rate, ease: "linear", repeat: Infinity, repeatDelay: 1.2 / rate } ) ); } let inView = true; const sync = () => { const play = inView && !document.hidden; for (const c of controls) { if (play) c.play(); else c.pause(); } }; const observer = new IntersectionObserver(([entry]) => { inView = entry.isIntersecting; sync(); }); observer.observe(root); document.addEventListener("visibilitychange", sync); return () => { for (const c of controls) c.stop(); observer.disconnect(); document.removeEventListener("visibilitychange", sync); }; }, [variant, cell, speed, scanLine, reduceMotion]); const size = `${cell}px ${cell}px`; const showScan = scanLine && !reduceMotion; if (variant === "perspective") { return ( <div ref={rootRef} aria-hidden className={cn("pointer-events-none absolute inset-0 overflow-hidden [container-type:size]", className)} style={style} {...props} > {/* Sizes in container units keep the horizon at the same height whatever the box size. */} <div className="absolute inset-x-[-200%] bottom-0 h-[500cqh] origin-bottom overflow-hidden" style={{ transform: "perspective(120cqh) rotateX(62deg)", maskImage: "linear-gradient(to top, #000 0%, #000 20%, transparent 80%)", }} > <div ref={floorRef} className="absolute inset-x-0 bottom-0" style={{ top: -cell, backgroundImage: lines(mix(color, 18)), backgroundSize: size }} /> {showScan && ( <div ref={scanRef} className="absolute inset-0" style={{ transform: "translateY(-100%)", background: `linear-gradient(to bottom, transparent 90%, ${mix(color, 5)} 98.5%, ${mix(color, 25)} 99.8%, transparent)`, }} /> )} </div> </div> ); } return ( <div ref={rootRef} aria-hidden className={cn( "pointer-events-none absolute inset-0 overflow-hidden", fade && "[mask-image:radial-gradient(ellipse_at_center,#000_40%,transparent_85%)]", className )} style={style} {...props} > <div className="absolute inset-0" style={{ backgroundImage: lines(mix(color, 8)), backgroundSize: size }} /> {showScan && ( <div ref={scanRef} className="absolute inset-0" style={{ transform: "translateY(-100%)", background: `linear-gradient(to bottom, transparent 70%, ${mix(color, 3)} 96%, ${mix(color, 20)} 99.6%, transparent)`, }} /> )} </div> ); }
The grid fills its nearest positioned parent. It is pointer-events-none, so it never blocks the content on top.
Usage
import { TechGrid } from "@/components/dusk/techy/tech-grid"
export function Hero() {
return (
<section className="relative overflow-hidden">
<TechGrid />
<div className="relative">{/* your content */}</div>
</section>
)
}Examples
Perspective floor
variant="perspective" tilts the grid into a receding floor that scrolls toward you, with a faint scan line moving down it. The horizon scales with the container.
Version 2.0 is here
Faster builds and a new CLI.
import { TechGrid } from "@/components/dusk/techy/tech-grid";
export default function TechGridPerspective() {
return (
<div className="relative flex h-80 w-full items-start justify-center overflow-hidden rounded-xl border border-white/10 bg-background pt-14">
<TechGrid variant="perspective" />
<div className="relative text-center">
<h3 className="text-3xl font-semibold tracking-tight text-white">Version 2.0 is here</h3>
<p className="mt-2 text-sm text-white/60">Faster builds and a new CLI.</p>
</div>
</div>
);
}Customizing
Change color, cellSize and speed, or switch off the scanLine.
import { TechGrid } from "@/components/dusk/techy/tech-grid";
export default function TechGridCustom() {
return (
<div className="grid w-full gap-4 sm:grid-cols-2">
<div className="relative flex h-56 items-end overflow-hidden rounded-xl border border-white/10 bg-background p-4">
<TechGrid cellSize={24} scanLine={false} />
<span className="relative font-mono text-xs text-white/70">cellSize=24 · no scan line</span>
</div>
<div className="relative flex h-56 items-end overflow-hidden rounded-xl border border-white/10 bg-background p-4">
<TechGrid variant="perspective" color="#a5b4fc" cellSize={28} speed={1.5} />
<span className="relative font-mono text-xs text-white/70">perspective · speed=1.5</span>
</div>
</div>
);
}API Reference
Any other div prop is passed to the root.
| Prop | Type | Default | Description |
|---|---|---|---|
| variant | "flat" | "perspective" | "flat" | Blueprint grid or receding floor. |
| color | string | "rgb(255 255 255)" | Line and scan color, mixed down to a faint tint. Any CSS color. |
| cellSize | number | 40 | Size of one grid cell in px. |
| speed | number | 1 | Speed multiplier for the floor and the scan line. |
| scanLine | boolean | true | Sweep a faint scan line across the grid. |
| fade | boolean | true | Fade the flat grid out toward the edges. |
| className | string | — | Merged onto the absolutely positioned root. |
Accessibility
- Decorative only: the root is
aria-hiddenandpointer-events-none, so nothing is blocked. - With prefers-reduced-motion the floor stops and the scan line is removed.
- Animations pause while the grid is off-screen or the tab is hidden, and stop on unmount.