# inflate

Letters puff up into round 3D shapes, like balloons or soft clay, that dent and wobble under the pointer.

Each letter swells into a soft, rounded volume, as if it were filled with air: straight strokes become round tubes, dots become domes and the joints of strokes bulge a little. A studio light from the upper left shades the volume, a glossy highlight runs along it and a soft shadow sits on the page under the letters. As the text comes into view the letters inflate from flat one after another with a springy overshoot. Where the pointer rests the skin dents in and nearby letters lean toward it; a press dents deeper, and on release the letters spring back with a wobble. The soft style looks like matte clay, and the jelly style like translucent gummy candy, clear at the rims and deeper in color where it is thick.

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

A candy shop's summer headline in pink balloon letters on a pastel background, puffing up one letter after another.

```html title="index.html"
<section class="if-shop">
  <p class="if-kicker">Sweet Spot · candy bar and soda fountain</p>
  <h2 class="if-title" data-dio="inflate">Sugar rush</h2>
  <p class="if-line">Forty kinds of gummies, hand-pulled taffy and floats in six flavors. Open from noon, every day of the summer.</p>
</section>
```

## Usage

Put it on: a heading, a label or the text inside a button, in a bold or display font. Not img, video, canvas, svg or form fields.

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

```html
<h1 data-dio="inflate">Bubble pop</h1>
```

In page transitions: Leaving a page the letters go flat and fade; entering, they puff up again.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'balloon' \| 'soft' \| 'jelly'` | `'balloon'` | balloon is glossy foil; soft is matte clay; jelly is clear gummy candy. |
| `trigger` (rebuilds) | `data-dio-trigger` | `'view' \| 'hover' \| 'always'` | `'view'` | view inflates as it shows; hover inflates on pointer, focus or tap; always starts round. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Color of the letters, any CSS color; empty keeps the color of each letter. |
| `depth` | `data-dio-depth` | `number` 0 to 2 | `1` | How far the letters puff out: 1 makes round tubes, 0 leaves them flat. |
| `gloss` | `data-dio-gloss` | `number` 0 to 1.5 | `0.7` | Strength of the highlights and of the sheen at the rims; 0 for none. |
| `squish` | `data-dio-squish` | `number` 0 to 1.5 | `1` | How deep the pointer dents the letters under it; 0 turns the dent off. |
| `tilt` | `data-dio-tilt` | `number` 0 to 20° | `10` | Largest lean of the letters near the pointer, degrees; 0 keeps them upright. |
| `duration` | `data-dio-duration` | `number` 0 to 3 s | `1.1` | Time one letter takes to inflate, overshoot included. |
| `stagger` | `data-dio-stagger` | `number` 0 to 0.3 s | `0.06` | Delay between neighboring letters as they inflate. |
| `delay` | `data-dio-delay` | `number` 0 to 2 s | `0` | Wait after the trigger, for a cascade. |
| `threshold` | `data-dio-threshold` | `number` 0 to 1 | `0.3` | Share of the element height in view, above the bottom tenth, before it plays. |

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

### Variants

- `style`: `balloon`, `soft`, `jelly`
  - `balloon` is glossy foil.
  - `soft` is matte clay.
  - `jelly` is clear gummy candy.
- `trigger`: `view`, `hover`, `always`
  - `view` inflates as it shows.
  - `hover` inflates on pointer, focus or tap.
  - `always` starts round.

## 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 only while something on it moves, then stops. Full rate while letters inflate or deflate and while the dent and the lean follow the pointer and spring back; none at rest, under a still pointer or with the pointer away. 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 letters are round from the start and stay still: no inflating, no dent and no lean, and no frames of their own. With trigger hover the label switches between flat and round without motion.

Runs on every device. A finger pressing the letters dents them and they spring back when it lifts; nothing follows a hover. With trigger hover a tap inflates the label and the next one lets it go flat.

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

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

## Cost and quality

Loads 13.1 KB the first time a page uses it. GPU: Two draws: a grid of about one vertex per 3 CSS px for each letter, raised in the vertex shader, with six texture reads per pixel for the light, and one quad for the shadow. Memory: A canvas of the text at twice its CSS size with mip levels, and a half-float field of it with a margin for the shadow, 8 bytes a texel, built once on the CPU in short steps.

- low: The text is rastered at 1 device pixel per CSS pixel instead of 2, and its field holds at most 600,000 texels instead of 1.6 million.

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

## Recipes

### Button labels that puff up on hover

With `trigger="hover"` the label stays plain text until the pointer or keyboard focus reaches the button, then its letters inflate in a quick wave and go flat again when it leaves; on a phone a tap inflates the label and the next tap lets it go. Put the effect on the text inside the button, not on the button: the effect draws the element it sits on in its place, so the button’s background, border and padding stay as they are. Shorter `duration` and `stagger` keep the wave quick.

Two pill buttons on a cream background, Order a box and See flavors, whose labels inflate when hovered.

```html title="index.html"
<div class="if-cta">
  <a class="if-button" href="/order"><span data-dio="inflate" data-dio-trigger="hover" data-dio-duration="0.7" data-dio-stagger="0.03">Order a box</span></a>
  <a class="if-button if-ghost" href="/flavors"><span data-dio="inflate" data-dio-trigger="hover" data-dio-style="soft" data-dio-duration="0.7" data-dio-stagger="0.03">See flavors</span></a>
</div>
```

### Matte clay for a craft studio

`style="soft"` turns the letters into matte clay: a broad soft light, no sharp highlight, and a darker seam where each letter meets the page. A lower `gloss` takes away the last of the sheen. It suits a wide, heavy font.

A pottery class poster on a pale gray background with the name Mud Club in orange clay letters.

```html title="index.html"
<section class="if-studio">
  <h2 class="if-name" data-dio="inflate" data-dio-style="soft" data-dio-gloss="0.5">Mud Club</h2>
  <p class="if-when">Wheel throwing for beginners · Tuesdays 6 to 8 p.m.</p>
</section>
```

### Gummy candy in its own color

`style="jelly"` makes the letters translucent: clear and bright at the rims, deeper in color where they are thick, and the page shows through them. `color` overrides the text color for the letters and their shadow.

```html
<h2 data-dio="inflate" data-dio-style="jelly" data-dio-color="#19b48a">Gummy bears</h2>
```

## Notes

The letters are built in 3D, not painted. A distance field of the glyphs is built once on the CPU, and the letters are inflated like a membrane under pressure, so straight strokes become round tubes, dots become domes and the joints of strokes bulge a little. Each letter is a mesh raised by that height and seen through the page camera, so it leans in perspective, and the normals of the surface take a studio light with a highlight and a soft shadow on the page. `depth` scales the height: 1 is round, larger is taller than wide.

The pointer dents the skin where it rests and deeper where it presses, the skin around the dent rises a little, and letters near it lean toward it. Everything springs back with a wobble when the pointer leaves or lets go. `squish` and `tilt` at 0 turn the dent and the lean off.

The text stays real text in the DOM: screen readers read it, search engines index it, and find in page works. While the letters are drawn the DOM text is hidden without being removed. With `trigger="hover"` the element is plain text at rest. Frames run only while letters inflate or go flat and while the dent and the lean move; at rest the effect draws nothing. Under reduced motion the letters are round from the start and do not move.

The effect looks best on bold or display fonts at 48 px and larger; hairlines of a thin serif inflate too, as fine glossy tubes. The canvas cannot draw `background-clip: text`, `text-shadow`, `-webkit-text-stroke` or vertical writing modes the way the browser does: 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.
- [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)
