# Horizon Grid
*URL: https://www.grettech.com/components/horizon-grid*

A synthwave scene for heroes: an endless neon grid floor racing toward a striped sun setting behind the horizon. Day and night palettes follow the theme. Pure CSS.

- Endless grid floor in true 3D perspective
- Striped sun that sets behind a glowing horizon
- GPU-only animation: no repaints, smooth on any device
- Light "vaporwave day" and dark night palettes follow the theme
- Pure CSS: renders on the server, no JavaScript; every colour is a prop

## Install with the shadcn CLI
```bash
npx shadcn@latest add https://www.grettech.com/api/registry/horizon-grid
```
With its demo: `npx shadcn@latest add https://www.grettech.com/api/registry/horizon-grid-demo`

**Dependencies:** npm: clsx, tailwind-merge

## Manual installation
**Step 1: Install dependencies**
Install the packages this component uses and the shadcn/ui components it builds on. It also needs the `cn` helper in `lib/utils.ts`, which `npx shadcn@latest init` adds.

```bash
npm install clsx tailwind-merge
```

**Step 2: Copy the source code**
Add these files to your project components directory.

File: `components/ui/horizon-grid.tsx`
```tsx
import { cn } from "@/lib/utils"
import * as React from "react"

export interface HorizonGridProps extends React.HTMLAttributes<HTMLDivElement> {
  /** Content shown over the scene */
  children?: React.ReactNode
  /** Sky gradient, top to horizon. Defaults follow light and dark mode. */
  sky?: [string, string]
  /** Ground colour below the horizon. Defaults follow light and dark mode. */
  ground?: string
  /** Sun gradient, top to bottom */
  sun?: [string, string, string]
  /** Colour of the grid lines and horizon glow. Defaults follow the theme. */
  gridColor?: string
  /** Horizon height in % from the top */
  horizon?: number
  /** Seconds for the grid to move one cell */
  speed?: number
  /** Grid cell size in px */
  cellSize?: number
  showSun?: boolean
}

// Shipped with the component so no global CSS is needed; React 19 hoists
// it to <head> once, however many grids are on the page
// One keyframes rule per cell size, with the distance as a literal: Chrome
// only runs animations on the GPU when keyframes don't use CSS variables
const keyframes = (cell: number) => `
@keyframes gridtic-horizon-scroll-${cell} { to { transform: translateY(${cell}px); } }
@media (prefers-reduced-motion: reduce) { .gridtic-horizon-floor { animation: none !important; } }
`

/** A soft-edged line through the middle of each cell, so it anti-aliases */
const line = (direction: string) =>
  `linear-gradient(${direction}, transparent calc(50% - 1.5px), var(--hg-grid) calc(50% - 0.75px) calc(50% + 0.75px), transparent calc(50% + 1.5px))`

/**
 * A synthwave scene: an endless neon grid floor rushing toward a striped sun
 * setting behind the horizon. Pure CSS with a transform-only animation, so it
 * renders on the server and runs on the GPU. A light "vaporwave day"
 * palette and a dark night palette follow the theme.
 */
export const HorizonGrid = React.forwardRef<HTMLDivElement, HorizonGridProps>(
  (
    {
      children,
      sky,
      ground,
      sun,
      gridColor,
      horizon = 58,
      speed = 0.8,
      cellSize = 56,
      showSun = true,
      className,
      style,
      ...props
    },
    ref
  ) => {
    // Props override the theme defaults set by the classes below
    const overrides = {
      ...(sky && { "--hg-sky-top": sky[0], "--hg-sky-bottom": sky[1] }),
      ...(ground && { "--hg-ground": ground }),
      ...(gridColor && { "--hg-grid": gridColor }),
      ...(sun && {
        "--hg-sun-1": sun[0],
        "--hg-sun-2": sun[1],
        "--hg-sun-3": sun[2],
      }),
    }

    return (
      <div
        ref={ref}
        className={cn(
          "relative isolate flex min-h-80 w-full items-center justify-center overflow-hidden",
          "[--hg-grid:#c026d3] [--hg-ground:#fdf4ff] [--hg-sky-bottom:#f5d0fe] [--hg-sky-top:#fdf4ff] [--hg-sun-1:#fde68a] [--hg-sun-2:#fb7185] [--hg-sun-3:#c026d3]",
          "dark:[--hg-grid:#e879f9] dark:[--hg-ground:#05010f] dark:[--hg-sky-bottom:#3b0a5c] dark:[--hg-sky-top:#07021a]",
          className
        )}
        style={
          {
            "--hg-cell": `${cellSize}px`,
            background: `linear-gradient(to bottom, var(--hg-sky-top), var(--hg-sky-bottom) ${horizon}%, var(--hg-ground) ${horizon}%)`,
            ...overrides,
            ...style,
          } as React.CSSProperties
        }
        {...props}
      >
        <style href={`gridtic-horizon-grid-${cellSize}`} precedence="default">
          {keyframes(cellSize)}
        </style>

        {showSun && (
          // Clipped at the horizon, so the sun sets behind it
          <div
            aria-hidden="true"
            className="absolute inset-x-0 top-0 -z-10 overflow-hidden"
            style={{ height: `${horizon}%` }}
          >
            <div
              className="absolute bottom-0 left-1/2 aspect-square w-[min(42%,340px)] -translate-x-1/2 translate-y-[28%] rounded-full"
              style={{
                background:
                  "linear-gradient(to bottom, var(--hg-sun-1), var(--hg-sun-2) 55%, var(--hg-sun-3))",
                boxShadow:
                  "0 0 120px 30px color-mix(in oklab, var(--hg-sun-2) 45%, transparent)",
                // Bands cut out of the lower half, thicker toward the horizon
                maskImage:
                  "linear-gradient(to bottom, #000 50%, transparent 50% 53%, #000 53% 60%, transparent 60% 64%, #000 64% 70%, transparent 70% 75%, #000 75%)",
              }}
            />
          </div>
        )}

        {/* Floor: a long plane hinged at the bottom edge and tilted away, so
            it stretches to the horizon (the vanishing point is the top of
            this box) and never passes the camera */}
        <div
          aria-hidden="true"
          className="absolute inset-x-0 bottom-0 -z-10 overflow-hidden [perspective-origin:50%_0%] [perspective:300px]"
          style={{ top: `${horizon}%`, background: "var(--hg-ground)" }}
        >
          <div className="absolute -inset-x-[150%] bottom-0 h-[1000%] origin-bottom [transform:rotateX(80deg)] overflow-hidden">
            {/* The grid layer is one cell taller than the plane and slides
                down by one cell, then loops: a GPU transform, no repaints */}
            <div
              className="gridtic-horizon-floor absolute inset-x-0 bottom-0 will-change-transform"
              style={{
                top: `-${cellSize}px`,
                backgroundImage: `${line("to bottom")}, ${line("to right")}`,
                backgroundSize: `${cellSize}px ${cellSize}px`,
                animation: `gridtic-horizon-scroll-${cellSize} ${speed}s linear infinite`,
              }}
            />
          </div>
          {/* Haze over the far floor hides the lines where they get too
              dense to draw cleanly */}
          <div
            className="absolute inset-0"
            style={{
              background:
                "linear-gradient(to bottom, var(--hg-ground) 0%, color-mix(in oklab, var(--hg-ground) 60%, transparent) 18%, transparent 45%)",
            }}
          />
        </div>

        {/* Horizon glow */}
        <div
          aria-hidden="true"
          className="absolute inset-x-0 -z-10 h-px"
          style={{
            top: `${horizon}%`,
            background: "var(--hg-grid)",
            boxShadow: "0 0 24px 6px var(--hg-grid)",
          }}
        />

        <div className="relative z-10 w-full">{children}</div>
      </div>
    )
  }
)
HorizonGrid.displayName = "HorizonGrid"

```

**Step 3: Framework Adjustments (Optional)**
If you are manually copying this code into a Vite or Remix project (without using the CLI), make sure to remove the `"use client";` directive from the very top of the file.

## Props
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| `children` | `React.ReactNode` | - | No | Content shown over the scene. |
| `sky` | `[string, string]` | `Pastel pink by day, deep violet by night (follows the theme)` | No | Sky gradient from the top to the horizon. |
| `ground` | `string` | `"#fdf4ff" light, "#05010f" dark` | No | Ground colour below the horizon. |
| `sun` | `[string, string, string]` | `["#fde68a", "#fb7185", "#c026d3"]` | No | Sun gradient, top to bottom. |
| `gridColor` | `string` | `"#c026d3" light, "#e879f9" dark` | No | Colour of the grid lines and the horizon glow. |
| `horizon` | `number` | `58` | No | Horizon height in % from the top. |
| `speed` | `number` | `0.8` | No | Seconds for the grid to move one cell; lower is faster. |
| `cellSize` | `number` | `56` | No | Grid cell size in px. |
| `showSun` | `boolean` | `true` | No | Shows the sun. |
| `className` | `string` | - | No | Extra classes for the scene. |
| `...props` | `React.HTMLAttributes<HTMLDivElement>` | - | No | Any other attributes, passed to the scene. |

## Usage
```tsx
"use client"

import { HorizonGrid } from "@/components/ui/horizon-grid"

export default function HorizonGridDemo() {
  return (
    <HorizonGrid
      horizon={64}
      className="h-[480px] items-start rounded-3xl pt-10"
    >
      <div className="flex flex-col items-center px-6 text-center">
        <p className="text-xs font-semibold tracking-[0.3em] text-fuchsia-700 uppercase dark:text-fuchsia-300">
          Now booking for 2027
        </p>
        <h2 className="mt-3 bg-linear-to-b from-neutral-950 to-fuchsia-800 bg-clip-text text-4xl font-bold tracking-tight text-transparent sm:text-6xl dark:from-white dark:to-fuchsia-200">
          Ride the next wave
        </h2>
        <p className="mt-4 max-w-md text-sm text-fuchsia-950/70 sm:text-base dark:text-fuchsia-100/70">
          Websites that feel like the future, built to load like the past.
        </p>
      </div>
    </HorizonGrid>
  )
}

```
