# neon

A heading becomes a 3D neon sign: round glass tubes that stutter on, light the wall and cast a shadow.

The letters become round glass tubes mounted a little in front of the page. Lit, the gas glows white hot along the middle of each tube and saturated at its sides, a highlight runs along the glass, and the tubes throw a soft colored light onto the wall behind them, where their shadow falls too. When the sign comes into view its tubes stutter on one after another like a real sign warming up, and once lit it buzzes now and then. The light that casts the shadow sits above the screen, so the shadow shifts as the page scrolls; a mouse near the sign takes its place, the shadow swings away from it, the highlights slide along the tubes and the sign turns a little toward it. The outline style bends one thin tube along the edge of each letter instead of filling it.

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

A basement bar's headline as a pink neon sign on a dark wall, its tubes stuttering on letter by letter and lighting the wall behind them.

```html title="index.html"
<section class="nn-bar">
  <p class="nn-kicker">Basement · 41 Canal Street</p>
  <h2 class="nn-sign" data-dio="neon">Open late</h2>
  <p class="nn-line">Natural wine, small plates and a record on the turntable until 2 a.m., Thursday to Sunday.</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 `neon`, so the attribute alone puts it on an element.

```html
<h2 class="sign" data-dio="neon">Open late</h2>
```

In page transitions: Leaving a page the tubes go dark from the last letter back and the glass fades; entering they light up in reading order.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'tube' \| 'outline'` | `'tube'` | tube makes each stroke a round tube; outline bends a thin tube along the edge. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'view' \| 'hover' \| 'always'` | `'view'` | view turns on as it shows; hover lights on pointer, focus or tap; always stays lit. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Color of the gas and its light, any CSS color; empty uses the text color. |
| `glow` | `data-dio-glow` | `number` 0 to 1.5 em | `0.5` | Radius of the light thrown on the wall, in ems of the font size; 0 for none. |
| `strength` | `data-dio-strength` | `number` 0 to 3 | `1` | Brightness of the light on the wall and around the tubes; 0 leaves bare tubes. |
| `depth` | `data-dio-depth` | `number` 0 to 0.4 em | `0.12` | How far the tubes stand off the wall, in ems; 0 mounts them flat on it. |
| `shadow` | `data-dio-shadow` | `number` 0 to 1 | `0.6` | Darkness of the shadow the tubes cast on the wall; 0 for none. |
| `tilt` | `data-dio-tilt` | `number` 0 to 12° | `5` | Largest turn of the sign toward a mouse near it, degrees; 0 keeps it still. |
| `flicker` | `data-dio-flicker` | `number` 0 to 1 | `0.3` | How often and how deep the lit sign buzzes and dims; 0 holds it steady. |
| `broken` | `data-dio-broken` | `number` 0 to 1 | `0` | Share of the letters that keep stuttering and going dark; 0 for none. |
| `seed` | `data-dio-seed` | `number` 1 to 100 | `1` | Picks the flicker, the broken letters and the turn-on; the same seed repeats. |

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

### Variants

- `style`: `tube`, `outline`
  - `tube` makes each stroke a round tube.
  - `outline` bends a thin tube along the edge.
- `trigger`: `view`, `hover`, `always`
  - `view` turns on as it shows.
  - `hover` lights on pointer, focus or tap.
  - `always` stays lit.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`presence`](/docs/api/inputs#presence), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-y). Draws at a steady rate while it is on screen and stops when it leaves. Full rate while tubes switch on or off and while the lamp or the sign follows the mouse, 30 a second while a tube flickers, none in between: a timer wakes the sign for its next flicker. With flicker and broken at 0 it draws nothing once lit, except on scroll. 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. The sign is lit from the start: no turn-on, no flicker, no broken letters, the shadow does not follow the scroll or the mouse, and it draws no frames of its own.

Runs on every device. No mouse lamp and no turn: the light stays above the screen. With trigger hover a tap switches the sign on and off.

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

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

## Cost and quality

Loads 12.7 KB the first time a page uses it. GPU: Three instanced draws of a quad per letter (wall light and shadow, bloom, tubes), at most three texture reads per pixel; nothing is blurred on the GPU. Memory: A canvas of the text at twice its CSS size, a distance field of it with its direction, and a small atlas of each letter’s light blurred once on the CPU.

- low: The text is rastered at 1 device pixel per CSS pixel instead of 2, and the distance field at half that.

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

## Recipes

### A menu that lights up on hover

With `trigger="hover"` each link stays dark glass until the pointer or keyboard focus reaches it, then its tubes catch in a quick stutter; on a phone a tap switches it on. Each link takes its color from its CSS `color`. `flicker="0"` keeps a lit link steady, so it draws nothing while the pointer rests on it.

A club menu of three uppercase links in red, cyan and lime that light up as neon when hovered.

```html title="index.html"
<nav class="nn-menu" aria-label="Club">
  <a class="nn-program" href="/program" data-dio="neon" data-dio-trigger="hover" data-dio-flicker="0">Program</a>
  <a class="nn-tickets" href="/tickets" data-dio="neon" data-dio-trigger="hover" data-dio-flicker="0">Tickets</a>
  <a class="nn-drinks" href="/bar" data-dio="neon" data-dio-trigger="hover" data-dio-flicker="0">Bar</a>
</nav>
```

### A motel sign with a dying letter

`style="outline"` bends one thin tube along the edge of each letter, the classic roadside look. `broken` picks a share of the letters, at least one, that keep stuttering and go dark for a while now and then; `seed` decides which. Between two stutters the sign draws nothing.

A red outline neon sign that reads Vacancy over a dark wall, one of its letters flickering out now and then.

```html title="index.html"
<div class="nn-motel">
  <h2 data-dio="neon" data-dio-style="outline" data-dio-trigger="always" data-dio-broken="0.12" data-dio-seed="4">Vacancy</h2>
  <p>Route 66 · Rooms from $59</p>
</div>
```

### On a light wall

In daylight the light of the tubes on the wall gives way to their shadow. The sign reads the background color behind it: on a light wall the glow is softer and the shadow plainer, so a sign on a pale shop front still stands off the wall. A larger `depth` moves the tubes and their shadow further apart.

```html
<h2 data-dio="neon" data-dio-trigger="always" data-dio-flicker="0" data-dio-depth="0.2" data-dio-shadow="0.8">Fresh flowers</h2>
```

## Notes

The sign is built in 3D, not painted: the tubes have a round section whose normals come from a distance field of the letters, so a highlight runs along each tube and slides as the light moves. They hang `depth` ems in front of the page, the light they throw lands on the wall behind them, and so does their shadow. The lamp for that shadow sits above the screen, so the shadow shifts as the page scrolls; a mouse near the sign takes its place, the shadow swings away from it and the sign turns a little toward it. The light on the wall is blurred once on the CPU when the sign is built, never per frame.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. While the sign is drawn the DOM text is hidden without being removed. Neon reads best in a medium or bold font and a saturated color on a dark background.

Frames run while tubes switch on or off and while the lamp or the sign follows the mouse; a flickering tube asks for 30 a second. Between flickers a timer wakes the sign, and with `flicker` and `broken` at 0 a lit sign draws nothing. Under reduced motion the sign is lit from the start, with no turn-on, no flicker and no broken letters, and the shadow and the sign stay still.

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. A `text-shadow` is fine: the sign draws its own light. `style`, `trigger` and `color` rebuild the effect when they change; a new `glow` blurs the light again after a short pause, and 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.
- [fire](/docs/effects/fire.md): The letters burn: flames rise from their tops, sparks drift up in depth and the firelight flickers on the page.
- [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.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
