grid
A grid floor in perspective running toward the viewer under a glowing horizon: neon synthwave, a blueprint or plain thin lines.
Live, one night only
Neon Nights at the Arcade Hall
- Date
- Mar 14
- Doors
- 22:00
- Tickets
- €25
Three synthwave sets, a retro game corner and a light show until 4 am.
Live preview needs WebGPU or WebGL 2. An event card for a synthwave night, with a neon grid floor running toward a striped sun beside the date and ticket price.
This example failed to draw.
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. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add grid<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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.gr-floor', 'grid', { style: 'neon', color: '#ff4fd8', background: '#0d0221', accent: '#ff8a3d', cells: 14, horizon: 0.5, speed: 0.4, sun: 0.5, thickness: 1.2, depth: 0.2, scroll: 0.3, fps: 30,})import { start } from '@dioramajs/diorama'import grid from '@dioramajs/backgrounds/grid'
const app = start()app.attach('.gr-floor', grid({ style: 'neon', color: '#ff4fd8', background: '#0d0221', accent: '#ff8a3d', cells: 14, horizon: 0.5, speed: 0.4, sun: 0.5, thickness: 1.2, depth: 0.2, scroll: 0.3, fps: 30,}))Page transitions
Fades with the page transition. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'neon' | 'blueprint' | 'minimal' | 'neon' |
|
colordata-dio-color | color | '#ff4fd8' | Color of the lines, any CSS color. |
backgrounddata-dio-background | color | '#0d0221' | Color of the floor and the sky. |
accentdata-dio-accent | color | '#ff8a3d' | Color of the horizon glow and the sun; with minimal, of the sun only; with blueprint, of the haze. |
cellsdata-dio-cells | number2 to 60 | 14 | Cells across the bottom edge: more makes a finer grid. |
horizondata-dio-horizon | number0.1 to 0.9 | 0.5 | Height of the horizon from the top, as a share of the element. |
speeddata-dio-speed | number0 to 2 | 0.4 | How fast the floor runs toward the viewer; 0 holds it. |
sundata-dio-sun | number0 to 1 | 0.5 | Size of the sun on the horizon; 0 hides it. |
thicknessdata-dio-thickness | number0.5 to 4 px | 1.2 | Width of the lines in CSS pixels. |
depthdata-dio-depth | number0 to 1 | 0.2 | How far the view turns with the pointer; 0 ignores the pointer. |
scrolldata-dio-scroll | number0 to 1 | 0.3 | How far the floor moves forward while the element crosses the viewport; 0 keeps it. |
fpsdata-dio-fps | number0 to 60 | 30 | Most frames a second the floor draws while it runs; 0 holds it still.At most low 15, medium 24 by quality tier. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, hover, pointer, progress, reducedMotion and 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. How a frame is decided.
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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { grid: { reducedMotion: 'off' } } })Cost and quality
- Download
- 1.9 KB min+gzip 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.
- Frames
- Draws while on screen
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | At most 15 frames a second. |
medium | At most 24 frames a second. |
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.
<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>.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%);}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.
Live preview needs WebGPU or WebGL 2. Pale blue grid lines on a deep blue floor running to a hazy horizon, with a thin circle for the sun.
This example failed to draw.
<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.
<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; sethorizonto 0.55 or more for room. Over the floor, put text on a card.blueprint: white or#eaf2fftext over the deep blue; the lines are pale, so keepthicknessat 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.