# fire

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

Flames rise from the tops of the strokes that face open air, in a plume built from the shape of the letters: white-yellow where they leave the strokes, orange higher up, red at the tips, swaying and torn into tongues by turbulence carried up through them, taller over one letter and lower over the next as the fire breathes. Over the strokes the flames thin out, so the text 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 rise in front of and behind the letters and cool from yellow to red as they climb. The firelight flickers on the page around the text in step with the flames, and the letters cast a soft shadow below. The embers style turns the letters into hot coals with light in their cracks and low flames; the candle style puts one calm, swaying flame on top of each letter.

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

A bonfire night poster whose headline burns: flames rise from its letters, sparks drift around it and firelight flickers on the page.

```html title="index.html"
<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>
```

## 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.

```html
<h1 data-dio="fire">Burn bright</h1>
```

In page transitions: Leaving a page the fire dies down and the letters fade with it; entering they catch fire again.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'flame' \| 'embers' \| 'candle'` | `'flame'` | flame burns tall; embers makes glowing coals; candle lights one calm flame per letter. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'loop' \| 'hover' \| 'view' \| 'scroll'` | `'loop'` | loop burns on; hover lights near the pointer; view flares up once; scroll follows the page. |
| `strength` | `data-dio-strength` | `number` 0 to 2 | `1` | Brightness of the flames, the sparks and the firelight; 0 puts the fire out. |
| `height` | `data-dio-height` | `number` 0.2 to 2 em | `0.9` | Height of the flames over the letters, in ems; embers and candle keep theirs lower. |
| `speed` | `data-dio-speed` | `number` 0 to 3 | `1` | Pace of the flames and the sparks; 0 holds the fire still. |
| `embers` | `data-dio-embers` | `number` 0 to 400 | `30` | Sparks in the air at once; candle sends up a third as many, 0 for none. At most low 10, medium 20. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Tint of the fire, any CSS color, such as a blue gas flame; empty for natural fire. |
| `char` | `data-dio-char` | `number` 0 to 1 | `0.4` | How dark the flames scorch the tops of the letters, recovering after; 0 for none. |
| `seed` (rebuilds) | `data-dio-seed` | `number` 1 to 100 | `1` | Picks the shape of the flames, the sparks and where the fire catches first. |

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

### Variants

- `style`: `flame`, `embers`, `candle`
  - `flame` burns tall.
  - `embers` makes glowing coals.
  - `candle` lights one calm flame per letter.
- `trigger`: `loop`, `hover`, `view`, `scroll`
  - `loop` burns on.
  - `hover` lights near the pointer.
  - `view` flares up once.
  - `scroll` follows the page.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`presence`](/docs/api/inputs#presence), [`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. 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. 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 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.

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

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

## Cost and quality

Loads 16.9 KB 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.

- low: At most 10 sparks, flames with less turbulence, and the text rastered at 1 device pixel per CSS pixel.
- medium: At most 20 sparks.

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

## 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.

A grill house menu of three uppercase links that burst into flames under the pointer.

```html title="index.html"
<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.

A carol service invitation whose light serif heading has a candle flame on every letter.

```html title="index.html"
<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.

```html
<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.

## Related

- [assemble](/docs/effects/assemble.md): Thousands of lit particles fly out of the depth around the page and gather into a heading.
- [blinds](/docs/effects/blinds.md): A heading printed across real 3D slats that turn over in a wave, lit and casting shadows, to show it.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [dust](/docs/effects/dust.md): A heading crumbles into fine sand that lifts off the page and drifts away in depth as it scrolls out, or on a click.
- [emboss](/docs/effects/emboss.md): Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
- [extrude](/docs/effects/extrude.md): A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
- [hologram](/docs/effects/hologram.md): A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.
- [inflate](/docs/effects/inflate.md): Letters puff up into round 3D shapes, like balloons or soft clay, that dent and wobble under the pointer.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
