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

fire

TextAlso in3D and product

@dioramajs/text/fireSource

The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.

View as Markdown
On this page

Bonfire Night · Saturday 4 November

Burn bright

Live music, mulled cider and the big fire on the beach from dusk. Bring a blanket and a friend.

Live preview needs WebGPU or WebGL 2. A bonfire night poster whose headline burns: flames rise from its letters, sparks drift around it and firelight flickers on the page.

This example failed to draw.

Switch the style and the trigger, or move the sliders. The hover trigger lights the letters near the pointer.
Params of fire
style

flame burns tall.

trigger

loop burns on.

Usage

Put it on a heading, a label or a short line of text, best on a dark background. Not img, video, canvas, svg or form fields. start() registers fire, 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 fire
<section class="fr-night">
<p class="fr-kicker">Bonfire Night · Saturday 4 November</p>
<h2 class="fr-title" data-dio="fire">Burn bright</h2>
<p class="fr-line">Live music, mulled cider and the big fire on the beach from dusk. Bring a blanket and a friend.</p>
</section>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.fr-title', 'fire', {
style: 'flame',
trigger: 'loop',
strength: 1,
height: 0.9,
speed: 1,
embers: 30,
char: 0.4,
})
import { start } from '@dioramajs/diorama'
import fire from '@dioramajs/text/fire'
const app = start()
app.attach('.fr-title', fire({
style: 'flame',
trigger: 'loop',
strength: 1,
height: 0.9,
speed: 1,
embers: 30,
char: 0.4,
}))

Page transitions

Leaving a page the fire dies down and the letters fade with it; entering they catch fire again. 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'flame' | 'embers' | 'candle''flame'
  • flame burns tall.
  • embers makes glowing coals.
  • candle lights one calm flame per letter.
triggerrebuildsdata-dio-trigger'loop' | 'hover' | 'view' | 'scroll''loop'
  • loop burns on.
  • hover lights near the pointer.
  • view flares up once.
  • scroll follows the page.
strengthdata-dio-strengthnumber0 to 21Brightness of the flames, the sparks and the firelight; 0 puts the fire out.
heightdata-dio-heightnumber0.2 to 2 em0.9Height of the flames over the letters, in ems; embers and candle keep theirs lower.
speeddata-dio-speednumber0 to 31Pace of the flames and the sparks; 0 holds the fire still.
embersdata-dio-embersnumber0 to 40030Sparks in the air at once; candle sends up a third as many, 0 for none.At most low 10, medium 20 by quality tier.
colorrebuildsdata-dio-colorstring''Tint of the fire, any CSS color, such as a blue gas flame; empty for natural fire.
chardata-dio-charnumber0 to 10.4How dark the flames scorch the tops of the letters, recovering after; 0 for none.
seedrebuildsdata-dio-seednumber1 to 1001Picks the shape of the flames, the sparks and where the fire catches first.

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, presence, reducedMotion and size . Draws at a steady rate while it is on screen and stops when it leaves. 30 a second while the fire burns and is on screen, none off screen. Hover and view draw nothing once the fire has died down and the char has faded, and view with embers stops once the coals settle; scroll draws while the text burns. 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 warm glow: the letters lit and the page warm around them, no moving flames and no sparks. Candles stand still, coals keep their glow, and nothing is drawn after.

Runs on every device. With trigger hover a tap lights the letters around it for a moment; focus on the element or its link lights them all.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { fire: { reducedMotion: 'off' } } })

Cost and quality

Download
16.9 KB min+gzip the first time a page uses it
GPU
A quad over the letters, one over the air above them for the flames (seven texture reads a pixel), one for the firelight around the text (two reads), and one small quad per spark or candle. Pixels with nothing to add are discarded.
Memory
A canvas of the text, a distance field of it, the plume the flames rise in, a small texture of the firelight and one of the heat of each letter.
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 10 sparks, flames with less turbulence, and the text rastered at 1 device pixel per CSS pixel.
mediumAt most 20 sparks.

Recipes

A menu that catches fire under the pointer

With trigger="hover" each link stays plain text until the pointer reaches it: the letters near the pointer catch fire, and when it moves on they die down and their char fades. Keyboard focus lights the whole link, and on a phone a tap lights the letters around it for a moment. Once the fire is out the link draws nothing.

Live preview needs WebGPU or WebGL 2. A grill house menu of three uppercase links that burst into flames under the pointer.

This example failed to draw.

<nav class="fr-menu" aria-label="Grill house">
<a
href="/starters"
data-dio="fire"
data-dio-trigger="hover"
data-dio-height="0.6"
>Starters</a>
<a
href="/grill"
data-dio="fire"
data-dio-trigger="hover"
data-dio-height="0.6"
>From the grill</a>
<a
href="/smoked"
data-dio="fire"
data-dio-trigger="hover"
data-dio-height="0.6"
>Smoked</a>
</nav>

Candles on a quiet heading

style="candle" puts one small flame on the top of each letter, with a blue base, a bright body and a soft glow on the page, swaying gently. It suits elegant pages, invitations and seasonal greetings. A candle sends up only a few sparks.

Silent night

Carols by candlelight · St Mary's · 24 December, 7 pm

Live preview needs WebGPU or WebGL 2. A carol service invitation whose light serif heading has a candle flame on every letter.

This example failed to draw.

Params of fire
<div class="fr-candle">
<h2
data-dio="fire"
data-dio-style="candle"
data-dio-embers="20"
>Silent night</h2>
<p>Carols by candlelight · St Mary's · 24 December, 7 pm</p>
</div>

Flare up once

trigger="view" sets the heading alight as it comes into view: the fire runs along the text from one letter, flares up, burns for a moment and dies down, and with style="embers" it settles to letters that glow like hot coals. After that nothing more is drawn.

<h2
data-dio="fire"
data-dio-trigger="view"
data-dio-char="0.6"
>Ignition</h2>

Notes

The fire is built from the shape of the letters, not painted over them. Flames leave the tops of the strokes that face open air (a closed counter in an o or an e barely burns) and rise in a plume that spreads sideways and is stopped by the ink. Turbulence carried up through the plume sways the flames and tears them into tongues, each a little taller or lower as the fire breathes, and the temperature sets the color: white-yellow where the flames leave the strokes, orange higher up, red at the tips. Over the strokes the flames thin out, so the heading stays readable. The tops of the letters glow like embers, their faces warm toward the fire and darken with soot where it burned. A few sparks fly in front of the text and behind it, so the fire has depth and shifts with the page as it scrolls. The firelight flickers on the page around the text in step with the flames and casts a soft shadow below the letters.

On a light page light would not show, so the flames are drawn more saturated with darker smoke at the tips, and the text stays readable. color tints the fire, for a blue gas flame or a brand color; empty keeps natural fire.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. The loop and scroll modes draw 30 frames a second while the text burns and is on screen; hover and view draw nothing once the fire is out. Under reduced motion the text holds a still warm glow with no moving flames and no sparks.

The canvas cannot draw some text the way the browser does: background-clip: text, -webkit-text-stroke and vertical writing modes. An element with any of them keeps its text as it is, and a warning in development names the reason. style, trigger, color and seed rebuild the effect; the other params change live.