# reflection

A soft reflection on a glossy floor under a product photo, without baking it into the image.

Below the image the picture is mirrored, as if the product stood on polished stone or glass: the reflection starts at the product's base, fades out over reach of the image's height and blurs with distance. For a cutout with transparent padding the base is its lowest solid row, so the reflection touches the product, not the edge of the file. A contact shadow can ground it, and a ripple turns the floor into still water.

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

Three books standing on a pale shelf, each with a soft reflection on the glossy surface below it.

```html title="index.html"
<div class="rf-shelf">
  <ul class="rf-wall">
    <li><img src="/media/books/blue-shore.webp" alt="The Blue Shore by Mara Ellison, a year of cyanotypes" width="900" height="1350" data-dio="reflection" data-dio-shadow="0.35" /></li>
    <li><img src="/media/books/low-water.webp" alt="Low Water by Ines Calder, notes from the tide line" width="900" height="1350" data-dio="reflection" data-dio-shadow="0.35" /></li>
    <li><img src="/media/books/salt-garden.webp" alt="Salt Garden, field notes" width="900" height="1350" data-dio="reflection" data-dio-shadow="0.35" /></li>
  </ul>
</div>
```

## Usage

Put it on: img, video.

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

```html
<img src="/shop/speaker.png" alt="Bookshelf speaker in walnut" data-dio="reflection" data-dio-shadow="0.35" style="margin-bottom: 160px" />
```

In page transitions: Fades with the page transition.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `strength` | `data-dio-strength` | `number` 0 to 1 | `0.35` | Opacity of the reflection at the base: 0 hides it and leaves only the shadow. |
| `reach` | `data-dio-reach` | `number` 0 to 1 | `0.45` | How far the reflection runs down, as a share of the element's height. |
| `blur` | `data-dio-blur` | `number` 0 to 40 px | `8` | Blur at the far end of the reflection, growing from sharp at the base: 0 is a mirror. At most low 0. |
| `gap` | `data-dio-gap` | `number` -40 to 40 px | `0` | Space between the base and the reflection; negative pulls it up. |
| `trim` | `data-dio-trim` | `boolean` | `true` | Mirror at the lowest solid row of a transparent picture and at the drawn bottom under object-fit; false mirrors at the bottom of the box. |
| `ripple` | `data-dio-ripple` | `number` 0 to 20 px | `0` | Sway of a water ripple in the reflection: 0 is a still floor. |
| `shadow` | `data-dio-shadow` | `number` 0 to 1 | `0` | Darkness of a soft contact shadow under the base: 0 draws none. |
| `fps` | `data-dio-fps` | `number` 1 to 60 | `30` | Frames a second the ripple draws at while visible. At most low 15. |

## Inputs and frames

Reads [`height`](/docs/api/inputs#input-height), [`size`](/docs/api/inputs#size), [`time`](/docs/api/inputs#time), [`width`](/docs/api/inputs#input-width). Draws at a steady rate while it is on screen and stops when it leaves. Once when it appears and on layout changes; with a ripple, at most fps a second while visible. None at rest. 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 ripple stands still; the reflection itself is not motion.

Runs on every device. The same as on desktop: the reflection does not react to input.

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

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

## Cost and quality

Loads 1.9 KB the first time a page uses it. GPU: Twelve texture reads per pixel of the reflection for the blur and eight for the shadow, only below the image. Memory: The image as a texture; the element itself stays DOM.

- low: No blur, one texture read per pixel of the reflection; the ripple at most 15 frames a second.

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

## Recipes

### A product cutout on a glossy shelf

For e-commerce product shots, a transparent PNG or WebP gets a reflection below it without baking one into the image. Leave room under the image with a margin: the reflection draws below the element’s box and never shifts the layout.

```html
<img
  src="/shop/speaker.png"
  data-dio="reflection"
  data-dio-shadow="0.35"
  style="margin-bottom: 160px"
/>
```

### A phone mockup on dark glass

A lower `strength`, a short `reach` and a little `blur` read as dark glass.

```html
<img
  src="/app/phone.png"
  data-dio="reflection"
  data-dio-strength="0.25"
  data-dio-reach="0.3"
  data-dio-blur="4"
/>
```

### A photo over still water

On a full photo the bottom edge is mirrored; `ripple` adds a gentle wave, as over water.

```html
<img
  src="/stays/boathouse.avif"
  data-dio="reflection"
  data-dio-strength="0.6"
  data-dio-reach="0.6"
  data-dio-ripple="6"
/>
```

## Notes

The reflection takes no clicks and adds nothing to the page layout; give the image room below with a margin. Under reduced motion the ripple stands still.

## 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.
- [Performance and quality](/docs/guides/performance.md)
