text-reveal
Headings rise, slide up, fade, pop or type into place letter by letter, word by word or line by line.
Northside Roasters
Roasted on Tuesday, at your door by Friday.
Live preview needs WebGPU or WebGL 2. A roastery headline that rises into place letter by letter, tipped back and blurred at first.
This example failed to draw.
Every switch and slider plays it again.
Usage
Put it on any element with text: a heading, a paragraph, a link. Not img, video, canvas, svg or form fields. Any font-stretch, font-variation-settings and font-feature-settings draw as on the page when the font comes from a readable @font-face (same origin, or a stylesheet served with CORS such as Google Fonts); otherwise such text stays as it is, as does text with text-shadow, a text stroke, background-clip: text or vertical writing. start() registers text-reveal, 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 text-reveal<div class="tr-hero"> <p class="tr-kicker">Northside Roasters</p> <h2 class="tr-headline" data-dio="text-reveal" >Roasted on Tuesday, at your door by Friday.</h2></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.tr-headline', 'text-reveal', { motion: 'rise', by: 'letter', duration: 0.9, stagger: 0.03, delay: 0, rise: 0.6, tilt: 35, blur: 0.5, threshold: 0.2,})import { start } from '@dioramajs/diorama'import textReveal from '@dioramajs/text/text-reveal'
const app = start()app.attach('.tr-headline', textReveal({ motion: 'rise', by: 'letter', duration: 0.9, stagger: 0.03, delay: 0, rise: 0.6, tilt: 35, blur: 0.5, threshold: 0.2,}))Page transitions
Leaving a page, the units go again in reverse order; entering, they rise in order. A flight to a text element lands on the DOM text. 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 |
|---|---|---|---|
byrebuildsdata-dio-by | 'letter' | 'word' | 'line' | 'letter' | Unit that moves as one; over 1500 letters it moves by words, over 1500 words by lines. |
triggerrebuildsdata-dio-trigger | 'view' | 'scroll' | 'view' |
|
motionrebuildsdata-dio-motion | 'rise' | 'mask' | 'fade' | 'pop' | 'type' | 'rise' |
|
durationdata-dio-duration | number0.2 to 3 s | 0.9 | Time one unit takes to land; type ignores it. |
staggerdata-dio-stagger | number0 to 0.3 s | 0.03 | Delay between neighboring units in reading order. |
delaydata-dio-delay | number0 to 2 s | 0 | Wait after the trigger, for a cascade. |
risedata-dio-rise | number0 to 2 em | 0.6 | How far below its place a unit starts, with rise. |
tiltdata-dio-tilt | number0 to 90° | 35 | How far a unit starts tipped back around its baseline, with rise. |
blurdata-dio-blur | number0 to 1 | 0.5 | How blurred a unit starts with rise and fade; 0 for sharp.At most low 0 by quality tier. |
thresholddata-dio-threshold | number0 to 1 | 0.2 | Share of the element height that must be in view, above the bottom tenth of the viewport, before it plays. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads height, presence, progress, size and y
. Draws only while something on it moves, then stops. Only while units move, and with the scroll trigger while scrolling; none at rest. How a frame is decided.
Reduced motion and touch
With reduced motion it is off and the element shows as plain HTML. Off: the text is shown as it is, and the engine does not load for it.
Runs on every device. The same as with a mouse: it follows the scroll.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { 'text-reveal': { reducedMotion: 'static' } } })Cost and quality
- Download
- 7.6 KB min+gzip the first time a page uses it
- GPU
- One instanced draw of a quad per unit, one texture read per pixel.
- Memory
- A canvas of the text at twice its CSS size with mip levels, kept while the element lives: about 2.5 MB for a 1200 x 200 heading.
- 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 | No blur, and the text is rastered at 1 device pixel per CSS pixel instead of 2. |
Recipes
A hero headline and its subline
Let the headline’s words slide up out of a mask, then fade the subline in line by line. A delay on the subline makes the two read as one entrance instead of two animations that start together.
Close the books in a day, not a week.
Ledgerline matches every bank line to its invoice as it arrives, so month-end is a review instead of a hunt.
Live preview needs WebGPU or WebGL 2. A finance app headline whose words slide up out of a mask, then a subline that fades in line by line.
This example failed to draw.
The subline starts 0.5 s after the headline.
<header class="tr-launch"> <h2 class="tr-launch-title" data-dio="text-reveal" data-dio-by="word" data-dio-motion="mask" data-dio-stagger="0.08" >Close the books in a day, not a week.</h2> <p class="tr-launch-sub" data-dio="text-reveal" data-dio-by="line" data-dio-motion="fade" data-dio-delay="0.5" data-dio-stagger="0.15" >Ledgerline matches every bank line to its invoice as it arrives, so month-end is a review instead of a hunt.</p></header>Section headings that follow the scroll
With data-dio-trigger="scroll" a heading plays as it rises from the bottom of the viewport to the middle, and plays backward when you scroll up. Use it for the headings between the sections of a long landing page, where each one marks a step of the story. Scroll past this example to see it.
How a bag gets to you
- We roast on Tuesday morning.
- It rests for a day and ships on Wednesday.
- It reaches you by Friday.
Live preview needs WebGPU or WebGL 2. A section heading whose words come in as it rises up the page and go back as it sinks.
This example failed to draw.
Scroll the page: the words come in as the heading rises to the middle of the viewport and go back as it sinks.
<section class="tr-steps"> <h2 class="tr-steps-title" data-dio="text-reveal" data-dio-by="word" data-dio-trigger="scroll" data-dio-stagger="0.2" >How a bag gets to you</h2> <ol> <li>We roast on Tuesday morning.</li> <li>It rests for a day and ships on Wednesday.</li> <li>It reaches you by Friday.</li> </ol></section>A longer stagger, 0.2 s here, spreads the words along the scroll; with the default they arrive almost together. threshold sets how much of the heading must be in view before it starts. A heading that is on screen when the page opens stays as it is until scrolling would have played it.
An editorial masthead
Lines that slide up out of their own band read like type being set. Break the lines yourself with <br> so each one is a phrase, and give them a longer stagger than letters need.
<h1 class="masthead" data-dio="text-reveal" data-dio-by="line" data-dio-motion="mask" data-dio-stagger="0.12"> The slow issue:<br />six makers who refuse to hurry</h1>A command that types itself
motion="type" shows each letter at once when its turn comes, so stagger alone sets the pace. On a developer site it makes the install line the first thing the reader watches happen.
Get started
npm install @dioramajs/diorama
Live preview needs WebGPU or WebGL 2. An install command typed one letter at a time.
This example failed to draw.
One letter every 0.05 s.
<div class="tr-term"> <p class="tr-term-label">Get started</p> <p class="tr-term-line"> <span aria-hidden="true">$</span> <code data-dio="text-reveal" data-dio-motion="type" data-dio-stagger="0.05" >npm install @dioramajs/diorama</code> </p></div>Notes
The element keeps its text as you wrote it, with no span per letter. Screen readers read words rather than single letters, search engines index the heading, and find in page works. While units move, a CSS filter hides the DOM text without removing it, so assistive technology still reads it, and once the last unit lands the heading is real, selectable text again. Under reduced motion the effect is off and the text shows at once.
Text on screen when the page opens is hidden until the effect is ready and then plays. If the engine takes over 3 seconds to get there, the text shows as it is instead of waiting longer.
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.
Keep it to headings, short paragraphs and labels. Over 1500 letters it moves by words, over 1500 words by lines, and each element keeps a raster of its text for as long as it lives.
by, trigger and motion rebuild the effect when they change. Set them in the markup rather than switching them while the text is on screen.