# extrude

A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.

The letters keep their font and layout but gain real depth: each one is a block extruded behind its face, with a rounded bevel that catches the light, walls shaded by which way they face and darker toward the back, and a soft shadow on the page behind. The depth recedes in perspective, so letters far from the center show more of their sides. As the pointer moves, the block turns to face it and the light slides over the bevels; with scroll it turns as the heading crosses the viewport. Other styles stack the glyphs as paper layers in your colors, or draw a flat long shadow.

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

A type festival headline in heavy ivory letters that stand out of a dark page as a beveled 3D block and turn toward the pointer.

```html title="index.html"
<div class="ex-hero">
  <p class="ex-kicker">Tokyo · 14 to 18 April 2027</p>
  <h2 class="ex-headline" data-dio="extrude">Type Week</h2>
  <p class="ex-line">Five days of talks, type design workshops and a night market of letterpress studios.</p>
</div>
```

## Usage

Put it on: a heading or short text in a large, heavy font. Not img, video, canvas, svg or form fields.

`start()` registers `extrude`, so the attribute alone puts it on an element.

```html
<h1 class="hero" data-dio="extrude">Build in 3D</h1>
```

In page transitions: The block fades with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'solid' \| 'layers' \| 'shadow'` | `'solid'` | solid is a lit, beveled block; layers stacks paper cutouts; shadow is a flat long shadow. |
| `by` (rebuilds) | `data-dio-by` | `'pointer' \| 'scroll' \| 'none'` | `'pointer'` | pointer turns it toward the pointer; scroll turns it as the page scrolls; none holds it. |
| `depth` | `data-dio-depth` | `number` 0 to 80 px | `24` | How far the depth reaches behind the face at rest; a long shadow runs 5 times this. |
| `layers` | `data-dio-layers` | `number` 1 to 12 | `4` | Number of paper layers behind the face in the layers style. |
| `tilt` | `data-dio-tilt` | `number` 0 to 30° | `12` | Largest turn of the block toward the pointer or with the scroll; 0 holds it. |
| `light` | `data-dio-light` | `number` 0 to 360° | `315` | Where the light comes from as a CSS angle, 0 above and 90 right; depth falls away from it. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Wall color for solid, paper base for layers, shadow color for shadow; empty derives it. |
| `colors` (rebuilds) | `data-dio-colors` | `string` | `''` | Colors of the paper layers from front to back, repeated; empty uses darker shades. |

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

### Variants

- `style`: `solid`, `layers`, `shadow`
  - `solid` is a lit, beveled block.
  - `layers` stacks paper cutouts.
  - `shadow` is a flat long shadow.
- `by`: `pointer`, `scroll`, `none`
  - `pointer` turns it toward the pointer.
  - `scroll` turns it as the page scrolls.
  - `none` holds it.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`size`](/docs/api/inputs#size), [`visible`](/docs/api/inputs#input-visible), [`width`](/docs/api/inputs#input-width), [`x`](/docs/api/inputs#input-x), [`y`](/docs/api/inputs#input-y). Draws only while something on it moves, then stops. While the depth grows in once, while the pointer moves or the block settles after it, and while scrolling; none at rest. 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 block is drawn at full depth without growing in, and it does not turn.

Runs on every device. With by pointer, a touch screen turns the block with the scroll instead, since there is no hover.

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

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

## Cost and quality

Loads 11.9 KB the first time a page uses it. GPU: One quad over the text and its depth: a march of about one texture read per device pixel of depth, a few reads for the bevel, walls and shadow. Memory: A canvas of the text at twice its CSS size with mip levels, and a distance field of it at up to a million samples, made once when the page is idle.

- low: The text is rastered at 1 device pixel per CSS pixel instead of 2, so the depth takes fewer steps.

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

## Recipes

### Paper layers in brand colors

`style="layers"` stacks copies of the letters behind the face like paper cutouts, each one a little farther back and shaded by the layer in front of it. `colors` lists the layers from front to back and repeats when there are more layers than colors; without it the layers are darker shades of the text color. A playful palette suits a summer camp, a festival or a kids’ brand.

A summer camp name in coral letters stacked over yellow, teal and navy paper layers on a cream page.

```html title="index.html"
<div class="ex-camp">
  <h2 class="ex-camp-title" data-dio="extrude" data-dio-style="layers" data-dio-colors="#ffd23f #2ec4b6 #1d3557" data-dio-depth="26">Camp Juniper</h2>
  <p>Seven-day summer sessions for ages 8 to 14. Canoes, campfires and a lake you can see the bottom of.</p>
</div>
```

### A flat long shadow on a colored band

`style="shadow"` draws the classic flat long shadow: a trail at 45 degrees that fades out at five times `depth`. Its color is the band behind the heading, darkened, and the trail is cut at the edge of that band. It does not turn, so it costs nothing after the first frame.

A coffee menu item in white capitals with a long teal shadow on a teal band.

```html title="index.html"
<section class="ex-band">
  <p>Today at the counter</p>
  <h2 class="ex-band-title" data-dio="extrude" data-dio-style="shadow" data-dio-depth="30">Flat white</h2>
</section>
```

### A block that turns with the scroll

With `by="scroll"` the block faces the middle of the viewport, so it tips one way as it enters at the bottom and the other way as it leaves at the top. A deeper block and a larger `tilt` make the turn read from far away.

```html
<h2 data-dio="extrude" data-dio-by="scroll" data-dio-depth="40" data-dio-tilt="18">Since 1998</h2>
```

## Notes

The solid style is lit like an object: the face has a rounded bevel that catches the light, the walls are shaded by the way they face and darken toward the back, and the block casts a soft shadow on the page behind it. `light` sets where the light comes from, and the depth falls away from it. The depth recedes in perspective, so letters far from the middle of the heading show more of their sides. As the block turns, the light slides across the bevels.

The heading stays real text in the DOM: screen readers read it, search engines index it, and find in page works. While the block is drawn a CSS filter hides the DOM text without removing it. A background or border on the heading itself is hidden with it, so put them on a wrapper.

The depth and the shadows are drawn on the canvas over the page, so leave room around the heading in the direction they fall: text right below a long shadow is covered by it.

Use a large, heavy font: the depth and the bevel need thick strokes. The depth grows in once when the heading first comes into view. After that nothing is drawn at rest; frames come only while the pointer moves, while the block settles, and while the page scrolls. On touch screens `by="pointer"` turns the block with the scroll instead. Under reduced motion the block is drawn at full depth and does not turn.

The canvas cannot draw some text the way the browser does: `background-clip: text`, `text-shadow`, `-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`, `by`, `color` and `colors` rebuild the effect when they change.

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