# coin

A coin, medal or token struck from a logo or a photo: it turns, catches the light and flips over.

The image becomes the face of a metal disc with a rim, as thick as a real coin, lying where the image was with a soft shadow under it. A transparent logo is struck into the metal: its shapes stand out in relief, in their own colors or in bare metal, and the field around them is polished metal that mirrors a small studio. A photo of a coin keeps its own look. The coin leans toward the pointer so the light runs over it, turns under a drag to show its edge and its back, and a click turns it over or tosses it so it lands on the other face.

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

A navy and coral compass logo struck into a gold coin with a raised rim; it leans toward the pointer as the light runs over the metal.

```html title="index.html"
<img class="coin" src="/media/coins/coin-logo.svg" alt="Northwind" width="512" height="512" data-dio="coin" tabindex="0" style="touch-action: pan-y" />
```

## Usage

Put it on: img: the front face, the circle in the middle of its box; a transparent PNG or SVG logo, or a photo of a coin cut out round. Without WebGL the plain image shows.

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

```html
<img src="/brand/logo.svg" alt="Northwind Bank" width="512" height="512" data-dio="coin" tabindex="0" />
```

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` | `'coin' \| 'medal' \| 'token'` | `'coin'` | Shape of the object. coin: a thin disc with a narrow rim and a reeded edge, for coins and tokens of crypto and fintech sites; medal: thicker, with a wide polished rim and a smooth edge, for awards and badges; token: a thick enamel token whose edge is striped in metal and white, for loyalty programs and games. |
| `motion` (rebuilds) | `data-dio-motion` | `'flip' \| 'toss' \| 'none'` | `'flip'` | What a click or Enter does. flip turns it over about its vertical axis; toss throws it up, tumbling, to land on the other face; none keeps the click for the page. |
| `back` (rebuilds) | `data-dio-back` | `string` | `''` | Back face image URL or color; empty strikes the front on the back too. A color makes a plain back of that color with the rim. |
| `metal` | `data-dio-metal` | `color` | `'#d4af5f'` | Color of the metal: the rim, the edge and the field around a logo. On a token, the color of its enamel. |
| `ink` | `data-dio-ink` | `number` 0 to 1 | `1` | How much the picture keeps its own colors: 1 prints them, 0 strikes it in bare metal, so only its relief shows. |
| `relief` | `data-dio-relief` | `number` 0 to 1 | `0.6` | How far the shapes of a transparent logo and the rim stand out: 0 keeps the face flat. |
| `yaw` | `data-dio-yaw` | `number` -180 to 180° | `0` | Rest turn; positive shows the right edge. |
| `pitch` | `data-dio-pitch` | `number` -70 to 70° | `0` | Rest tilt; positive shows the top edge. |
| `tilt` | `data-dio-tilt` | `number` 0 to 35° | `14.3` | How far it leans toward the pointer: 0 turns the lean off. |
| `turn` | `data-dio-turn` | `number` -720 to 720° | `0` | Turns while the page scrolls past: 360 is a whole turn from entering the viewport to leaving it. 0 turns it off. |
| `spin` | `data-dio-spin` | `number` -360 to 360 deg/s | `0` | Idle turn while nobody touches it, pausing under the pointer and for 1.5 s after: 0 turns it off. |
| `drag` | `data-dio-drag` | `boolean` | `true` | Turns and tips it under a drag, 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`: `coin`, `medal`, `token`
- `motion`: `flip`, `toss`, `none`
  - `toss` throws it up, tumbling, to land on the other face.
  - `none` keeps the click for the page.

## 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), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`width`](/docs/api/inputs#input-width). Draws only while something on it moves, then stops. Only while it turns, leans, coasts after a drag, flips, and while spin turns it; none at rest, and pointer moves elsewhere draw nothing. Scroll draws frames only with turn. 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. A click or Enter turns it over at once, without the flip or the toss; dragging and arrow keys still turn it, without coasting.

Runs on every device. Nothing leans. A tap flips it, unless the image sits in a link or a button. 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: { coin: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 5.3 KB the first time a page uses it. GPU: A disc of about seven hundred triangles; five reads of the picture per pixel of a face for its relief, no environment map. Memory: The front image, and the back image when given.

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

## Recipes

### A logo struck as a coin

Give the image a transparent background: a PNG, or an SVG with a width and a height in the file. Its opaque shapes are struck into the face and stand out in `relief`; the transparent field around them is polished metal in `metal`. `ink` keeps the logo’s own colors at 1 and strikes it in bare metal at 0, which suits a monochrome mark.

```html
<img
  src="/brand/logo.svg"
  width="512"
  height="512"
  data-dio="coin"
  data-dio-metal="#c8ccd2"
  data-dio-ink="0"
/>
```

### An award medal that lands on its back

`style="medal"` makes a thicker disc with a wide polished rim, and `motion="toss"` throws it up on a click or Enter: it tumbles and lands on the other face. `back` takes the reverse as an image or a color.

A gold medal with a blue enamel center and a white star; a click tosses it up and it lands showing Best Studio 2026 on its back.

```html title="index.html"
<img class="coin" src="/media/coins/medal-front.webp" alt="Best Studio 2026, gold" width="600" height="600" data-dio="coin" data-dio-style="medal" data-dio-motion="toss" data-dio-back="/media/coins/medal-back.webp" tabindex="0" />
```

### Tokens that turn with the scroll

`turn` turns a coin as the page scrolls past it, so a row of tokens shows its edges and backs without any pointer, on touch screens too. A negative `turn` goes the other way. `style="token"` is a thick enamel token with a striped edge, colored by `metal`.

Three coins in a row: a green token with a leaf, a gold coin with a mountain, a silver coin with a compass struck in relief; they turn as the page scrolls.

```html title="index.html"
<div class="tokens">
  <img src="/media/coins/token-logo.webp" alt="Leaf club token" width="512" height="512" data-dio="coin" data-dio-style="token" data-dio-metal="#1f6f5c" data-dio-turn="180" />
  <img src="/media/coins/coin-front.webp" alt="One Altitude token, 2026" width="600" height="600" data-dio="coin" data-dio-back="/media/coins/coin-back.webp" data-dio-turn="-180" />
  <img src="/media/coins/coin-logo.svg" alt="Northwind in silver" width="512" height="512" data-dio="coin" data-dio-metal="#c8ccd2" data-dio-ink="0" data-dio-relief="1" data-dio-turn="180" />
</div>
```

## Notes

The coin is the circle in the middle of the image’s box, its diameter the shorter side. A photo of a coin should be cut out round, with transparent corners; a square photo loses its corners.

An SVG becomes a picture at the size written in its file, so give it a `width` and a `height` at least as large as the coin is shown. The image keeps its alt text for screen readers, and without WebGL the plain image shows.

The coin draws only while it moves: a lean, a drag, a flip, the scroll with `turn` or the idle `spin`. A coin inside a link keeps the link’s click and does not flip on it.

`style`, `motion` and `back` 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.
- [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.
- [label](/docs/effects/label.md): A flat label wrapped around a can, a bottle or a jar that turns to show all of it.
- [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)
