Skip to documentation content

Perspective Grid

A grid floor that recedes to a horizon, with lines that thin and fade with distance and an optional slow scroll.

perspective-grid-demo

Overview

Perspective Grid draws a flat floor of square cells seen from above, receding toward a horizon. Lines are crisp at the front and thin with distance, and each direction fades out before its cells get too small to draw cleanly, so the far floor never shimmers. Nothing is drawn above the horizon.

The background is transparent and the lines use currentColor by default, so the grid follows the text color in light and dark themes. An optional glow lights the horizon. Use it under a launch headline, an event page, or an empty state.

Installation

npm install honestui

Usage

import { PerspectiveGrid } from "honestui/shaders"

<div className="relative h-96 bg-background text-foreground">
  <PerspectiveGrid className="absolute inset-0" glow={0.3} glowColor="#3b82f6" />
  <h1 className="relative pt-16 text-center text-3xl font-medium">Launch week</h1>
</div>

Put headings above the horizon, where the canvas is empty, so the lines never cross the text.

Accessibility

Perspective Grid is decorative and its canvas is hidden from assistive technology. Keep text and actions in normal HTML.

The floor scrolls only while speed is not 0. Scrolling stops while the grid is offscreen or the tab is hidden, and a still frame shows when the user prefers reduced motion. Without WebGL2 the container shows only its own background.

API Reference

PropTypeDefaultDescription
colorstring"currentColor"Line color. Any CSS color.
opacitynumber0.3Line opacity at the front of the floor, from 0 to 1.
cellSizenumber64Width of one cell at the bottom edge, in CSS pixels.
lineWidthnumber1Line width at the bottom edge, in CSS pixels.
horizonnumber0.55Height of the horizon, from 0 (bottom) to 1 (top).
tiltnumber0.5Camera angle, from 0 (looking down, square cells) to 1 (grazing, flat cells).
fadenumber0.6How far the floor fades before the horizon, from 0 (sharp) to 1 (long fade).
glownumber0Soft band of light along the horizon, from 0 to 1.
glowColorstring–Color of the horizon glow. Defaults to color.
speednumber0.35Cells per second the floor moves toward the viewer. 0 keeps it still.
pausedbooleanfalseRenders a still frame instead of animating.
classNamestring–Class for sizing and positioning the container.
childrenReactNode–Content drawn above the grid.