# hologram

A heading becomes a 3D hologram: projected from a glowing emitter, built of slices in depth, crossed by scan lines.

A small emitter disc lies below the text, tipped toward you, with a lit ring, a turning ring of dashes and a bright core; it lights the page around it and throws a faint cone of light up through the text. The letters float in front of the page as several translucent slices stacked in depth: the front one solid and bright, the ones behind showing only the edges, so the text has volume. Fine scan lines cross it, a brighter band sweeps up through it, rows shimmer sideways, the color splits into red and blue fringes at the edges, and now and then the projection stutters or a band tears sideways. It sways slowly a few degrees and tips toward a pointer near it, and the parallax between the slices shows the depth. The card style mounts the slices on a dark holographic trading card with a foil border and a glossy foil in front: tipping it with the pointer shifts the slices against each other and sweeps a rainbow sheen across, and it keeps its last pose. The ghost style drops the projector: a cool, pale apparition that fades in from noise, drifts back and forth in depth and trails echoes behind it.

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

A satellite network launch page whose title is projected as a cyan hologram from an emitter disc, scanned in from the bottom.

```html title="index.html"
<section class="hg-launch">
  <p class="hg-kicker">Live keynote · 18:00 UTC</p>
  <h2 class="hg-title" data-dio="hologram">Orbital 7</h2>
  <p class="hg-line">The first satellite network you can rent by the minute. Join the stream for the unveiling.</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 `hologram`, so the attribute alone puts it on an element.

```html
<h1 data-dio="hologram">Launch day</h1>
```

In page transitions: The projection fades with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'projector' \| 'card' \| 'ghost'` | `'projector'` | projector stands on an emitter; card sits on a foil card that tilts; ghost trails echoes. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'view' \| 'hover' \| 'loop'` | `'view'` | view scans in as it shows; hover powers up on pointer, focus or tap; loop shimmers all the time. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Color of the projection and its light, any CSS color; empty uses cyan (ghost: ice blue). |
| `layers` | `data-dio-layers` | `number` 1 to 12 | `6` | Slices stacked in depth; 1 draws a flat projection. |
| `depth` | `data-dio-depth` | `number` 0 to 1 em | `0.3` | Depth of the stack of slices, in ems of the font size. |
| `scan` | `data-dio-scan` | `number` 0 to 2 | `1` | Strength of the scan lines, the sweep and the row shimmer; 0 for a clean projection. |
| `flicker` | `data-dio-flicker` | `number` 0 to 1 | `0.4` | How often the projection stutters, drops out or tears; 0 holds it steady. |
| `sway` | `data-dio-sway` | `number` 0 to 20° | `6` | Largest slow turn of the hologram, degrees; 0 keeps it still. |
| `tilt` | `data-dio-tilt` | `number` 0 to 20° | `8` | Largest tip toward a pointer near it, degrees (card: 1.8 times); 0 ignores it. |

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

### Variants

- `style`: `projector`, `card`, `ghost`
  - `projector` stands on an emitter.
  - `card` sits on a foil card that tilts.
  - `ghost` trails echoes.
- `trigger`: `view`, `hover`, `loop`
  - `view` scans in as it shows.
  - `hover` powers up on pointer, focus or tap.
  - `loop` shimmers all the time.

## 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. trigger view: full rate while it scans in (about 1.5 s), then none. hover: 30 a second while powered up, full rate while powering up or down, none at rest. loop: 30 a second while on screen, none off screen. Full rate while it tips toward the pointer. 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 hologram at full power: no scan-in, no sweep, no shimmer, no flicker, no sway, no tip; it draws no frames of its own.

Runs on every device. No tip toward the pointer. With trigger hover a tap powers it up and down.

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

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

## Cost and quality

Loads 16.6 KB the first time a page uses it. GPU: Four draws: the light on the page, the emitter, the cone and one instanced quad per slice with five texture reads per pixel. Memory: A canvas of the text at twice its CSS size, with its mip levels for the glow.

- low: The text is rastered at 1 device pixel per CSS pixel instead of 2.

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

## Recipes

### A call to action that powers up on hover

With `trigger="hover"` the hologram rests at half power, still and readable, and powers up when the pointer or keyboard focus reaches it: the emitter brightens, the scan lines start to run and the text begins to sway. On a phone a tap switches it. Once the pointer leaves it powers down and draws nothing.

```html
<a href="/beta" data-dio="hologram" data-dio-trigger="hover" data-dio-color="#ffb84a">Join the beta</a>
```

### A holographic trading card

`style="card"` mounts the slices on a dark card with a foil border and a glossy foil in front. Tip it with the pointer: the slices shift against each other behind the foil and a rainbow sheen sweeps across. The card keeps its last pose when the pointer leaves, so it draws nothing at rest.

```html
<h2 data-dio="hologram" data-dio-style="card" data-dio-color="#7cf3ff">Rare #07</h2>
```

### A ghost

`style="ghost"` drops the projector: a pale, cool apparition that fades in from noise, drifts back and forth in depth and trails its echoes behind it. With `trigger="loop"` it keeps drifting while it is on screen.

```html
<h2 data-dio="hologram" data-dio-style="ghost" data-dio-trigger="loop">Apparition</h2>
```

## Notes

The hologram is built in 3D, not painted: the text is a stack of `layers` translucent slices spread over `depth` ems in front of the page, the emitter is a disc lying below it and the cone of light a real cone between them. As the hologram sways and tips toward the pointer, the slices shift against each other in perspective and the depth shows. The emitter lights the page around it.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. While the hologram is drawn the DOM text is hidden without being removed. The default color is cyan; `color` takes any CSS color. On a light page the projection is drawn darker over the paper instead of adding light.

With `trigger="view"` it draws frames only while it scans in, then rests; `hover` draws 30 frames a second while powered up; `loop` draws 30 a second while on screen and none off screen. Under reduced motion the hologram is still and at full power: no scan-in, no sweep, no flicker and no sway.

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` and `color` rebuild the effect when they change; 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.
- [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)
