extrude
A headline becomes a solid 3D block: beveled letters with lit side walls, seen in perspective, that turn toward the pointer.
Tokyo · 14 to 18 April 2027
Type Week
Five days of talks, type design workshops and a night market of letterpress studios.
Live preview needs WebGPU or WebGL 2. 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.
This example failed to draw.
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. 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.
npx @dioramajs/diorama add extrude<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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.ex-headline', 'extrude', { style: 'solid', by: 'pointer', depth: 24, tilt: 12, light: 315,})import { start } from '@dioramajs/diorama'import extrude from '@dioramajs/text/extrude'
const app = start()app.attach('.ex-headline', extrude({ style: 'solid', by: 'pointer', depth: 24, tilt: 12, light: 315,}))Page transitions
The block fades with the page. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'solid' | 'layers' | 'shadow' | 'solid' |
|
byrebuildsdata-dio-by | 'pointer' | 'scroll' | 'none' | 'pointer' |
|
depthdata-dio-depth | number0 to 80 px | 24 | How far the depth reaches behind the face at rest; a long shadow runs 5 times this. |
layersdata-dio-layers | number1 to 12 | 4 | Number of paper layers behind the face in the layers style. |
tiltdata-dio-tilt | number0 to 30° | 12 | Largest turn of the block toward the pointer or with the scroll; 0 holds it. |
lightdata-dio-light | number0 to 360° | 315 | Where the light comes from as a CSS angle, 0 above and 90 right; depth falls away from it. |
colorrebuildsdata-dio-color | string | '' | Wall color for solid, paper base for layers, shadow color for shadow; empty derives it. |
colorsrebuildsdata-dio-colors | string | '' | Colors of the paper layers from front to back, repeated; empty uses darker shades. |
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, height, reducedMotion, size, visible, width, x and 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. 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. 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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { extrude: { reducedMotion: 'off' } } })Cost and quality
- Download
- 11.9 KB min+gzip 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.
- Frames
- Idle at rest
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | The text is rastered at 1 device pixel per CSS pixel instead of 2, so the depth takes fewer steps. |
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.
Camp Juniper
Seven-day summer sessions for ages 8 to 14. Canoes, campfires and a lake you can see the bottom of.
Live preview needs WebGPU or WebGL 2. A summer camp name in coral letters stacked over yellow, teal and navy paper layers on a cream page.
This example failed to draw.
<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.
Today at the counter
Flat white
Live preview needs WebGPU or WebGL 2. A coffee menu item in white capitals with a long teal shadow on a teal band.
This example failed to draw.
<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.
<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.