Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

gradient

Backgrounds

@dioramajs/backgrounds/gradientSource

A living background of four soft color blobs or of aurora curtains, mixed in OKLab, without banding, with a light film grain.

View as Markdown
On this page

Live stream, May 20, 18:00 CET

Launch week: Studio 5

Multiplayer editing, a new color engine and offline mode, shown live by the team that built them.

Save a seat

Live preview needs WebGPU or WebGL 2. A launch card whose cover is four soft blobs of navy, violet, coral and gold drifting into one another under a light film grain.

This example failed to draw.

Four soft blobs of color drift slowly over the element on looping paths that take minutes to repeat, their edges bent by noise. They lean toward the pointer and shift as the page scrolls. Colors mix in OKLab, so two colors meet through a clean middle instead of a muddy gray, and every pixel is dithered, so smooth ramps show no bands. A light film grain sits on top; set grain to 0 for a clean gradient or around 0.08 for a film look. The aurora style draws the first color as a night sky and the other three as curtains of light that wave along it, sharp at their lower edge and rising in uneven rays.

Palette

Ink suits the aurora style.

Params of gradient
style

mesh drifts four soft blobs into a wash of color, for most heroes and sections.

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 gradient, 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.

Terminal window
npx @dioramajs/diorama add gradient
<article class="gd-launch">
<div
class="gd-wash"
aria-hidden="true"
data-dio="gradient"
></div>
<div class="gd-info">
<p class="gd-kicker">Live stream, May 20, 18:00 CET</p>
<h2>Launch week: Studio 5</h2>
<p>Multiplayer editing, a new color engine and offline mode, shown live by the team that built them.</p>
<a href="/launch">Save a seat</a>
</div>
</article>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.gd-wash', 'gradient', {
style: 'mesh',
color1: '#0b1d3a',
color2: '#3a2b8c',
color3: '#e35d6a',
color4: '#f6c177',
speed: 0.2,
scale: 1,
warp: 0.4,
attract: 0.15,
scroll: 0.25,
grain: 0.03,
fps: 30,
})
import { start } from '@dioramajs/diorama'
import gradient from '@dioramajs/backgrounds/gradient'
const app = start()
app.attach('.gd-wash', gradient({
style: 'mesh',
color1: '#0b1d3a',
color2: '#3a2b8c',
color3: '#e35d6a',
color4: '#f6c177',
speed: 0.2,
scale: 1,
warp: 0.4,
attract: 0.15,
scroll: 0.25,
grain: 0.03,
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.

ParamTypeDefaultDescription
stylerebuildsdata-dio-style'mesh' | 'aurora''mesh'
  • mesh drifts four soft blobs into a wash of color, for most heroes and sections.
  • aurora draws the first color as a dark sky with the other three as waving curtains of light, for a night or tech hero over a dark page.
color1data-dio-color1color'#0b1d3a'Color of the first blob, any CSS color; with aurora, the sky.
color2data-dio-color2color'#3a2b8c'Color of the second blob; with aurora, the first curtain.
color3data-dio-color3color'#e35d6a'Color of the third blob; with aurora, the second curtain.
color4data-dio-color4color'#f6c177'Color of the fourth blob; with aurora, the third curtain.
speeddata-dio-speednumber0 to 10.2How fast the blobs travel along their paths.
scaledata-dio-scalenumber0.3 to 31Size of the blobs: below 1 sharper patches, above 1 softer washes.
warpdata-dio-warpnumber0 to 10.4How much noise bends the blobs’ edges.
attractdata-dio-attractnumber0 to 10.15How far the blobs lean toward the pointer while it is over the element.
scrolldata-dio-scrollnumber0 to 10.25How far the blobs move along their paths while the element crosses the viewport.
graindata-dio-grainnumber0 to 0.20.03Strength of the film grain, one CSS pixel per grain; 0 leaves only the dithering.
fpsdata-dio-fpsnumber0 to 6030Most frames a second the drift draws; 0 holds it still.At most low 15, medium 24 by quality tier.
octavesrebuildsdata-dio-octavesnumber1 to 32Layers of noise in the warp, 1 to 3.At most low 1 by quality tier.
seedrebuildsdata-dio-seednumber1 to 1001Paths of the blobs and shape of the noise.

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. The grain changes with those frames and adds none. 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 gradient: the blobs and the grain stop, and neither the pointer nor scroll moves them.

Runs on every device. The blobs lean toward 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: { gradient: { reducedMotion: 'off' } } })

Cost and quality

Download
2.3 KB min+gzip the first time a page uses it
GPU
One pass over the element: one to three reads of a small noise tile, four exponentials and a hash per pixel.
Memory
A 64 × 64 noise tile shared by every gradient on the page.
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.

TierWhat changes
lowAt most 15 frames a second, one layer of noise in the warp.
mediumAt most 24 frames a second.

Recipes

Behind a SaaS hero

Put the gradient on an empty aria-hidden element that fills the hero, and start the app with canvas: 'behind' so the heading and buttons sit over the canvas. The element’s CSS background is what visitors see until the engine draws, and all the time without WebGL, so give it the same colors.

<header class="hero">
<div
class="hero-bg"
aria-hidden="true"
data-dio="gradient"
data-dio-color1="#0a1a3f"
data-dio-color2="#3d5afe"
data-dio-color3="#00c2a8"
data-dio-color4="#e8f0ff"
></div>
<h1>Payroll that runs on the 25th, every month</h1>
<a class="cta" href="/signup">Start a free trial</a>
</header>
.hero {
position: relative;
isolation: isolate;
min-height: 80vh;
}
.hero-bg {
position: absolute;
inset: 0;
z-index: -1;
background: linear-gradient(135deg, #0a1a3f, #3d5afe 55%, #00c2a8);
}
src/main.ts
import { start } from '@dioramajs/diorama'
export const app = start({ canvas: 'behind' })

Keep the hero itself without a background color, or it covers the canvas behind it.

Aurora over a dark hero

The aurora style turns the first color into a night sky and the other three into curtains of light. Pick a near-black first color and three bright ones: it suits a night, travel or developer brand on a dark page.

Live preview needs WebGPU or WebGL 2. Green, blue and violet curtains of light waving over a dark navy sky.

This example failed to draw.

<div
class="gd-sky"
aria-hidden="true"
data-dio="gradient"
data-dio-style="aurora"
data-dio-color1="#050b1a"
data-dio-color2="#2bd59a"
data-dio-color3="#4f7cff"
data-dio-color4="#b45cff"
></div>

Film grain for a studio intro

Raise grain to around 0.08 for a printed, filmic surface, and speed a little so the blobs visibly travel on the first screen of a portfolio.

<section class="intro">
<div
class="intro-bg"
aria-hidden="true"
data-dio="gradient"
data-dio-color1="#1b1410"
data-dio-color2="#7a3b2e"
data-dio-color3="#d9a066"
data-dio-color4="#f2e3c9"
data-dio-grain="0.08"
data-dio-speed="0.2"
></div>
<h1>Halden Studio, interiors and objects</h1>
</section>

A calm backdrop for a long page

With fps at 0 the blobs stay where they are and move only as the page scrolls, so a long article or a pricing page gets a background that never draws at rest. Turn the grain off as well when text sits right over it.

<div
class="backdrop"
aria-hidden="true"
data-dio="gradient"
data-dio-color1="#f4efe6"
data-dio-color2="#e7d8f5"
data-dio-color3="#cfe7e1"
data-dio-color4="#fbe3c8"
data-dio-fps="0"
data-dio-scroll="0.6"
data-dio-grain="0"
></div>

Notes

The docs canvas sits above the page, so the examples here draw nothing over the gradient: with the canvas above, the gradient covers whatever is inside its box. Put text over a gradient with canvas: 'behind', as in the first recipe.

Colors are any CSS colors, oklch() included. The effect mixes them in OKLab, so two hues meet through a clean middle instead of a gray band, and it dithers every pixel, so dark ramps show no steps.

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 it. On the low tier it draws at most 15 frames a second with one layer of noise, which keeps it cheap on phones.

style, octaves and seed rebuild the effect when they change. The colors, speeds and grain change live.