# tone

Photos in brand colors: a duotone or a halftone, with color back on hover.

In duotone the lightness of each pixel picks a color on the line from the darker to the lighter of color and background in OKLab; the defaults give monochrome. In halftone dots of color sit on background in a grid of cell px at angle, sized so each cell keeps the light of the photo: a color lighter than background gives light dots on a dark ground that grow in the highlights. With reveal the photo fades back to color on hover, or shows color in a spot at the pointer.

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

A photo of surf breaking over brown rocks, shown in black and white, as a duotone or as a halftone of dots.

```html title="index.html"
<img src="/media/coast/surf-1440.avif" alt="Surf breaking over brown rocks at the foot of the cliffs" width="1440" height="960" data-dio="tone" />
```

## Usage

Put it on: img, video.

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

```html
<img src="/team/ana.avif" alt="Ana Ruiz, head of housekeeping" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="fade" />
```

In page transitions: Fades with the page transition; a flight carries the toned copy.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'duotone' \| 'halftone'` | `'duotone'` | duotone maps lightness to two colors; halftone draws dots sized by tone. |
| `color` | `data-dio-color` | `color` | `'#000000'` | Ink: the halftone dots. Lighter than background gives light dots on a dark ground. |
| `background` | `data-dio-background` | `color` | `'#ffffff'` | Paper behind the dots. In duotone the darker of color and background takes the shadows. |
| `strength` | `data-dio-strength` | `number` 0 to 1 | `1` | 0 shows the original photo, 1 the full tone. |
| `contrast` | `data-dio-contrast` | `number` 0 to 2 | `1` | Contrast of lightness before toning. |
| `cell` | `data-dio-cell` | `number` 2 to 32 px | `6` | Step of the halftone grid in CSS px. |
| `angle` | `data-dio-angle` | `number` 0 to 90° | `45` | Angle of the halftone grid. |
| `reveal` (rebuilds) | `data-dio-reveal` | `'none' \| 'fade' \| 'spot' \| 'view'` | `'none'` | none keeps the tone; fade brings color back on hover; spot shows color in a circle at the pointer; view brings it back while the image is in the middle half of the viewport, which works on touch screens too. |
| `radius` | `data-dio-radius` | `number` 20 to 400 px | `140` | Radius of the spot. |
| `duration` | `data-dio-duration` | `number` 0 to 2 s | `0.4` | Length of the fade to color and back. |

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

### Variants

- `style`: `duotone`, `halftone`
  - `duotone` maps lightness to two colors.
  - `halftone` draws dots sized by tone.
- `reveal`: `none`, `fade`, `spot`, `view`
  - `none` keeps the tone.
  - `fade` brings color back on hover.
  - `spot` shows color in a circle at the pointer.
  - `view` brings it back while the image is in the middle half of the viewport, which works on touch screens too.

## Inputs and frames

Draws only while something on it moves, then stops. Only while the color fades or the spot moves; none at rest. view decides in the frames the scroll draws anyway. 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. fade takes 0.15 s, and spot acts as fade.

Runs on every device. The tone stays: fade and spot need a hovering pointer. view works on touch.

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

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

## Cost and quality

Loads 2.1 KB the first time a page uses it. GPU: One texture read and OKLab conversions per pixel. Memory: The image only.

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

## Recipes

### Room cards in the brand’s colors

Photos from different shoots look like one set once they share two colors. Give every card the brand’s ink and paper, and `reveal="fade"` brings the real color back under the pointer, so the reader still sees what the room looks like before booking it.

Three hotel room photos in navy and cream that turn back to color under the pointer.

```html title="index.html"
<ul class="rooms">
  <li>
    <img src="/media/hotel/ocean-room.avif" alt="The Ocean Room: a white bed with a red throw by doors open to a balcony" width="800" height="600" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="fade" />
    <p>Ocean Room <span>from $310</span></p>
  </li>
  <li>
    <img src="/media/hotel/glass-room.avif" alt="The Glass Room: a bed under tall steel windows that look over the hills" width="800" height="600" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="fade" />
    <p>Glass Room <span>from $380</span></p>
  </li>
  <li>
    <img src="/media/hotel/twin-room.avif" alt="The Twin with Fireplace: a tea tray on a side table by a garden window" width="800" height="600" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="fade" />
    <p>Twin with Fireplace <span>from $260</span></p>
  </li>
</ul>
```

### Light dots on a dark site

On a dark page, make `color` the light one: the dots are then light on a dark ground and grow in the highlights, like a screen print on black paper. A lineup of acts photographed by different people reads as one poster.

Two instrument photos as light blue halftone dots on dark navy, as on a festival lineup.

```html title="index.html"
<ul class="stages">
  <li>
    <img src="/media/festival/cello.webp" alt="The f-hole, bridge and strings of a seventeenth-century cello" width="960" height="1200" data-dio="tone" data-dio-style="halftone" data-dio-color="#7fd3ff" data-dio-background="#081634" />
    <p><b>Vesper Array</b> Friday, 21:40</p>
  </li>
  <li>
    <img src="/media/festival/flugelhorn.webp" alt="A silver flugelhorn with three rotary valves against black" width="960" height="1200" data-dio="tone" data-dio-style="halftone" data-dio-color="#7fd3ff" data-dio-background="#081634" />
    <p><b>Signal Fires</b> Saturday, 23:10</p>
  </li>
</ul>
```

### Team photos that turn to color on phones

`fade` and `spot` need a pointer that hovers, so on a phone the photos would stay toned. `reveal="view"` brings the color back while a photo crosses the middle half of the viewport, as the reader scrolls a team page.

```html
<img
  src="/team/leo.avif"
  data-dio="tone"
  data-dio-color="#1d2a3a"
  data-dio-background="#f4e3c3"
  data-dio-reveal="view"
/>
```

### The same look without WebGL

Before the engine loads, and on devices without WebGL, the photo shows in color. A CSS filter gives a close black and white for the default look; the copy draws over it once it runs.

```css
img[data-dio~="tone"] {
  filter: grayscale(1);
}
```

## Notes

The tone changes how a photo looks, not what it says: its `alt` stays the same. Do not use it on pictures that carry information in their color, such as charts, maps or the color choices of a product.

For halftone, keep `cell` at 4 px or more. Smaller dots fall between the pixels of a standard screen and show a moiré pattern.

`style` and `reveal` rebuild the effect; the colors, `strength` and the grid change live, so a theme switch can write `color` and `background` from code.

## Related

- [bend](/docs/effects/bend.md): Scroll speed bends the image like paper and splits its color channels.
- [compare](/docs/effects/compare.md): Two pictures in one box, before and after, split by a line you drag, hover or scroll.
- [flare](/docs/effects/flare.md): A lens flare or a glossy light sweep over a photo that follows the pointer or the scroll.
- [frost](/docs/effects/frost.md): Frosted glass over a photo, or over the whole page, that the pointer wipes clear and that slowly fogs back.
- [glitch](/docs/effects/glitch.md): A digital glitch in short bursts: blocks slide sideways, color channels split, scanlines flicker.
- [image](/docs/effects/image.md): Draws the image or video unchanged, as a GL copy that page flights and other effects build on.
- [liquid](/docs/effects/liquid.md): The pointer leaves a fluid trail on a photo that settles back like water.
- [parallax](/docs/effects/parallax.md): The image drifts inside its frame with the pointer and the scroll; with a depth map, in 2.5D.
- [Reduced motion](/docs/guides/reduced-motion.md)
