# grid

A grid floor in perspective running toward the viewer under a glowing horizon: neon synthwave, a blueprint or plain thin lines.

The lower part of the element is a floor of square cells seen from just above, its lines running toward the viewer and meeting at the horizon. The upper part is the sky. Neon draws bright lines with a soft halo over a dark floor, the sky warming to the accent color at the horizon and a sun with bands cut through its lower half. Blueprint draws pale lines on a blue paper color with every fifth line heavier and the sun as a drawn circle. Minimal draws thin lines that fade out toward the horizon over a flat color, with the sun as a flat disc. Lines keep their width in CSS pixels and blend into an even tone where they crowd near the horizon, so the floor never shimmers. The pointer turns the view a little and the scroll moves the floor forward.

Module `backgrounds`, category Backgrounds. Import `@dioramajs/backgrounds/grid`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/backgrounds/src/grid.ts)

An event card for a synthwave night, with a neon grid floor running toward a striped sun beside the date and ticket price.

```html title="index.html"
<article class="gr-gig">
  <div class="gr-floor" aria-hidden="true" data-dio="grid"></div>
  <div class="gr-info">
    <p class="gr-kicker">Live, one night only</p>
    <h2>Neon Nights at the Arcade Hall</h2>
    <dl>
      <div><dt>Date</dt><dd>Mar 14</dd></div>
      <div><dt>Doors</dt><dd>22:00</dd></div>
      <div><dt>Tickets</dt><dd>€25</dd></div>
    </dl>
    <p>Three synthwave sets, a retro game corner and a light show until 4 am.</p>
  </div>
</article>
```

## Usage

Put it on: an empty decorative element behind the content, such as an aria-hidden div filling a hero; its CSS background is the look without WebGL.

`start()` registers `grid`, so the attribute alone puts it on an element.

```html
<header class="hero"><div class="hero-bg" aria-hidden="true" data-dio="grid"></div><h1>Neon Nights, Friday 22:00</h1></header>
```

In page transitions: Fades with the page transition.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'neon' \| 'blueprint' \| 'minimal'` | `'neon'` | neon, glowing lines and a striped sun, for gaming, music events and synthwave looks; blueprint, pale lines on blue paper with heavier major lines, for engineering, hardware and developer tools; minimal, thin lines fading into a flat color, for calm tech and SaaS pages. |
| `color` | `data-dio-color` | `color` | `'#ff4fd8'` | Color of the lines, any CSS color. |
| `background` | `data-dio-background` | `color` | `'#0d0221'` | Color of the floor and the sky. |
| `accent` | `data-dio-accent` | `color` | `'#ff8a3d'` | Color of the horizon glow and the sun; with minimal, of the sun only; with blueprint, of the haze. |
| `cells` | `data-dio-cells` | `number` 2 to 60 | `14` | Cells across the bottom edge: more makes a finer grid. |
| `horizon` | `data-dio-horizon` | `number` 0.1 to 0.9 | `0.5` | Height of the horizon from the top, as a share of the element. |
| `speed` | `data-dio-speed` | `number` 0 to 2 | `0.4` | How fast the floor runs toward the viewer; 0 holds it. |
| `sun` | `data-dio-sun` | `number` 0 to 1 | `0.5` | Size of the sun on the horizon; 0 hides it. |
| `thickness` | `data-dio-thickness` | `number` 0.5 to 4 px | `1.2` | Width of the lines in CSS pixels. |
| `depth` | `data-dio-depth` | `number` 0 to 1 | `0.2` | How far the view turns with the pointer; 0 ignores the pointer. |
| `scroll` | `data-dio-scroll` | `number` 0 to 1 | `0.3` | How far the floor moves forward while the element crosses the viewport; 0 keeps it. |
| `fps` | `data-dio-fps` | `number` 0 to 60 | `30` | Most frames a second the floor draws while it runs; 0 holds it still. At most low 15, medium 24. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `neon`, `blueprint`, `minimal`
  - `neon` glowing lines and a striped sun, for gaming, music events and synthwave looks.
  - `blueprint` pale lines on blue paper with heavier major lines, for engineering, hardware and developer tools.
  - `minimal` thin lines fading into a flat color, for calm tech and SaaS pages.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`hover`](/docs/api/inputs#hover), [`pointer`](/docs/api/inputs#pointer), [`progress`](/docs/api/inputs#progress), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size). Draws at a steady rate while it is on screen and stops when it leaves. Up to fps frames a second while on screen, none off screen or at fps 0; pointer and scroll draw at full rate. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. A still floor: it does not run, and neither the pointer nor scroll moves it.

Runs on every device. The view turns with a finger while it is on the screen; scrolling works as usual.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { grid: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 1.9 KB the first time a page uses it. GPU: One pass over the element with a little math per pixel, no textures. Memory: None beyond the shared plane.

- low: At most 15 frames a second.
- medium: At most 24 frames a second.

See [the quality plugin](/docs/effects/quality).

## Recipes

### A synthwave hero for a music night

Put the grid on an empty `aria-hidden` element that fills the hero and start the app with `canvas: 'behind'`. Keep the heading in the sky above the horizon, where the background is darkest.

```html
<header class="hero">
  <div
    class="hero-bg"
    aria-hidden="true"
    data-dio="grid"
    data-dio-horizon="0.62"
  ></div>
  <h1>Neon Nights, Friday 22:00</h1>
  <a class="cta" href="/tickets">Get tickets</a>
</header>
```

```css
.hero {
  position: relative;
  isolation: isolate;
  min-height: 80vh;
  color: #fff;
}
.hero-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, #0d0221 0 40%, #ff8a3d 62%, #0d0221 62%);
}
```

```ts title="src/main.ts"
import { start } from '@dioramajs/diorama'

export const app = start({ canvas: 'behind' })
```

### A blueprint for a hardware page

`blueprint` draws pale lines on blue paper with every fifth line heavier and the sun as a drawn circle. The colors below work well together.

Pale blue grid lines on a deep blue floor running to a hazy horizon, with a thin circle for the sun.

```html title="index.html"
<div class="gr-print" aria-hidden="true" data-dio="grid" data-dio-style="blueprint" data-dio-color="#d6e6ff" data-dio-background="#0d3b8c" data-dio-accent="#9cc3ff" data-dio-cells="24" data-dio-sun="0.4" data-dio-speed="0.2"></div>
```

### Calm lines for a developer tool

`minimal` draws thin lines that fade out toward the horizon over a flat color, without glow. A gray line color on a near-black background, `sun` at 0 and a slow `speed` give a quiet tech backdrop.

```html
<div
  class="bg"
  aria-hidden="true"
  data-dio="grid"
  data-dio-style="minimal"
  data-dio-color="#9aa4b2"
  data-dio-background="#0b0d12"
  data-dio-sun="0"
  data-dio-speed="0.2"
></div>
```

## Readable text

- `neon`: white text in the sky above the horizon; set `horizon` to 0.55 or more for room. Over the floor, put text on a card.
- `blueprint`: white or `#eaf2ff` text over the deep blue; the lines are pale, so keep `thickness` at 1.2 or below under body text.
- `minimal`: light text such as `#e6e8ec`; the lines stay faint enough for text anywhere.

## Notes

The docs canvas sits above the page, so the examples here keep text beside the grid. Put text over it with `canvas: 'behind'`, as in the first recipe.

Lines keep their width in CSS pixels at any distance and blend into an even, fading tone where they crowd near the horizon, so the floor never shimmers. The grid draws without textures.

It draws up to `fps` frames a second while it is on screen and none off screen; the pointer and scroll draw at full rate while they move the floor. With `depth` at 0 the pointer draws nothing. On the low tier it draws at most 15 frames a second.

`style` rebuilds the effect when it changes. Colors, cell count, horizon, speed, sun and line width change live.

## Related

- [blobs](/docs/effects/blobs.md): Soft blobs of brand color drifting behind a hero: merging like a lava lamp, as blurred orbs or as glossy glass drops.
- [clouds](/docs/effects/clouds.md): A sky of soft layered clouds for the time of day, daylight, a sunset or a moonlit night, drifting in the wind and parting on scroll.
- [dots](/docs/effects/dots.md): A dot grid behind a hero or in a card that answers the pointer: dots near it grow, move aside or glow, then settle back.
- [gradient](/docs/effects/gradient.md): A living background of four soft color blobs or of aurora curtains, mixed in OKLab, without banding, with a light film grain.
- [stars](/docs/effects/stars.md): A night sky of twinkling stars in depth layers that lean with the pointer and the scroll, with shooting stars and a warp flight.
- [waves](/docs/effects/waves.md): Topographic contour lines or flowing wave lines across a hero or footer, slowly changing and shifted by scroll.
- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [Performance and quality](/docs/guides/performance.md)
- [Reduced motion](/docs/guides/reduced-motion.md)
