# label

A flat label wrapped around a can, a bottle or a jar that turns to show all of it.

The label image is wrapped around a 3D container standing in the box of the element: printed on an aluminium can, glued on a glass bottle with a foil cap, or around a glass jar with a lid. It keeps its proportions, so its width decides how far around the body it reaches. The container turns as the page scrolls past and under a drag, leans toward the pointer, and the light runs over the metal, the glass and the print.

Module `model`, category 3D and product. Import `@dioramajs/model/label`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/model/src/label.ts)

A drinks can with a blue and cream Harbor Pale Ale label; it turns as the page scrolls and leans toward the pointer, the light running over the aluminium.

```html title="index.html"
<img class="can" src="/media/labels/label-can.webp" alt="Harbor Pale Ale label: 5.2% ABV, brewed with Citra hops, 330 ml" width="1240" height="560" data-dio="label" tabindex="0" style="touch-action: pan-y" />
```

## Usage

Put it on: img: the flat label, its whole width as printed; the container stands in the box of the image, as tall as fits. Without WebGL the plain label shows.

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

```html
<img src="/beer/pale-ale-label.webp" alt="Harbor Pale Ale label: 5.2% ABV, brewed with Citra hops" width="1240" height="560" data-dio="label" style="width: 240px; height: 360px; object-fit: contain" />
```

In page transitions: Leaves by dithering its pixels away while shrinking to 96%, and its shadow fades with it.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'can' \| 'bottle' \| 'jar'` | `'can'` | Kind of container. can: a 330 ml drinks can, the label printed all around its body, for beer, soda and coffee; bottle: a 750 ml bottle of colored glass with a foil cap, the label on its body, for wine, spirits and oils; jar: a squat glass jar with a twist lid, for cosmetics, honey, coffee and sauces. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Color of the body: the metal of a can, the glass of a bottle, what fills a jar. Empty takes the default of the style: aluminium, green glass, amber. |
| `cap` (rebuilds) | `data-dio-cap` | `string` | `''` | Color of the cap: the lid of a can, the foil of a bottle, the lid of a jar. Empty takes the default of the style. |
| `yaw` | `data-dio-yaw` | `number` -180 to 180° | `0` | Rest turn; 0 shows the middle of the label. |
| `pitch` | `data-dio-pitch` | `number` -35 to 35° | `8` | Rest tilt; positive shows the top, as seen from a little above. |
| `tilt` | `data-dio-tilt` | `number` 0 to 25° | `6.9` | How far it leans toward the pointer: 0 turns the lean off. |
| `turn` | `data-dio-turn` | `number` -720 to 720° | `180` | Turns while the page scrolls past: 360 is a whole turn from entering the viewport to leaving it, 180 shows the label from one end to the other. 0 turns it off. |
| `spin` | `data-dio-spin` | `number` -180 to 180 deg/s | `0` | Idle turn while nobody touches it, pausing under the pointer and for 1.5 s after: 0 turns it off. |
| `gloss` | `data-dio-gloss` | `number` 0 to 1 | `0.5` | Shine of the light on the print: 0 is matte paper. |
| `drag` | `data-dio-drag` | `boolean` | `true` | Turns it under a drag and tips it a little, and with the arrow keys when it has a tabindex. |
| `shadow` | `data-dio-shadow` | `number` 0 to 1 | `0.5` | Density of the shadow on the page. |

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

### Variants

- `style`: `can`, `bottle`, `jar`

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`opacity`](/docs/api/inputs#opacity), [`presence`](/docs/api/inputs#presence), [`progress`](/docs/api/inputs#progress), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`width`](/docs/api/inputs#input-width). Draws only while something on it moves, then stops. While the page scrolls with turn, and while it leans, coasts after a drag, eases a key step, or spin turns it; none at rest, and pointer moves elsewhere draw nothing. 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. It rests as posed: no lean, spin or scroll turn. Dragging and arrow keys still turn it, without coasting.

Runs on every device. Nothing leans; the scroll turns it. A finger turns it only when the element has `touch-action: pan-y` or `none`, and tips it only with `none`; otherwise the gesture scrolls the page.

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

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

## Cost and quality

Loads 4.4 KB the first time a page uses it. GPU: One body of about two thousand triangles with a simple light, no environment map. Memory: The label image.

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

## Recipes

### A wine bottle turned by a drag

`style="bottle"` puts the label on a 750 ml bottle of colored glass with a foil cap. A wine label is narrow, so it covers part of the body, as on a real bottle. `turn="0"` stops the scroll turn and leaves the bottle to a drag and the arrow keys.

A dark green wine bottle with a cream Hillside Riesling 2024 label, turned a little to the left; a drag turns it all the way round.

```html title="index.html"
<img class="bottle" src="/media/labels/label-wine.webp" alt="Hillside Riesling 2024 label: 750 ml, 12% vol" width="800" height="960" data-dio="label" data-dio-style="bottle" data-dio-turn="0" data-dio-yaw="-20" tabindex="0" style="touch-action: pan-y" />
```

### A jar with a colored lid

`style="jar"` is a squat glass jar with a twist lid. `color` is what fills the jar, seen through the glass, and `cap` is the lid. A higher `pitch` shows the top of the lid.

A glass jar of amber honey with a gold lid and a dark label with honeycomb and Wildflower Honey on it.

```html title="index.html"
<img class="jar" src="/media/labels/label-jar.webp" alt="Wildflower honey label: raw, 250 g" width="1500" height="500" data-dio="label" data-dio-style="jar" data-dio-color="#c98a1b" data-dio-cap="#b8902f" data-dio-pitch="16" />
```

## Notes

Use the flat label as it goes to print, its whole width. The label keeps its proportions: its height takes the label band of the container and its width decides how far around it reaches. A label longer than the body goes once round and gets a lower band. A label with transparent edges, such as a die-cut shape, shows the glass or the metal around it.

Size the image’s box for the container and keep the label undistorted with `object-fit: contain`: the container stands in the box as tall as fits. Without WebGL the flat label shows in the same box, all of it readable.

The container draws only while it moves: the scroll with `turn`, a drag, the lean or the idle `spin`. On touch screens the scroll turns it; a finger turns it only when the image has `touch-action: pan-y` or `none`.

`style`, `color` and `cap` rebuild the effect; every other param changes live.

## Related

- [book](/docs/effects/book.md): A cover image made a 3D book that turns to show its spine and opens on hover.
- [box](/docs/effects/box.md): A product box built from pictures of its faces: turn it, tilt it, open its lid.
- [coin](/docs/effects/coin.md): A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.
- [device](/docs/effects/device.md): A screenshot or a video shown in a 3D phone, tablet, laptop or browser window.
- [explode](/docs/effects/explode.md): An exploded view of a model: its parts move apart as the section scrolls.
- [hotspots](/docs/effects/hotspots.md): Feature callouts pinned to points of a model, real buttons that follow it as it turns.
- [model](/docs/effects/model.md): A glTF model fitted into the element, lit, turnable and recolored from markup.
- [panorama](/docs/effects/panorama.md): A 360° photo in a box that turns by drag, keys and gyroscope, with hotspots.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
