# emboss

Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.

The element becomes a piece of material in its own background color, with the text as a real relief built from the shape of every letter: raised like a book cover, pressed in like a business card, printed into thick paper with ink in the bottom, or stood up on a wax seal. A lamp follows the pointer and drifts as the page scrolls, so the walls of the letters catch the light on one side and fall into shadow on the other, the letters cast soft shadows on the surface, and the fibres, grain, brushing or speckle of the material glint across the whole card. Small print stays printed in its color.

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

A bookbinder's business card in cream cotton paper on a dark desk, its name raised out of the paper and its small print inked in brown.

```html title="index.html"
<div class="eb-desk">
  <div class="eb-lift">
    <div class="eb-card" data-dio="emboss">
      <p class="eb-name">Hollis &amp; Vane</p>
      <p class="eb-role">Bookbinding and restoration since 1932</p>
      <p class="eb-meta">14 Calder Row, Edinburgh · hollisvane.co.uk</p>
    </div>
  </div>
</div>
```

## Usage

Put it on: a card, cover, label or heading with a background color and short text in a bold font; text without a background is pressed into the page as it is. Not img, video, canvas, svg or form fields.

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

```html
<div class="card" data-dio="emboss" data-dio-style="letterpress"><h3>Ines Albrecht</h3><p>Bookbinder, Leipzig</p></div>
```

In page transitions: The surface fades with the page.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `style` (rebuilds) | `data-dio-style` | `'emboss' \| 'deboss' \| 'letterpress' \| 'stamp'` | `'emboss'` | emboss raised; deboss pressed in; letterpress an inked impression; stamp a wax seal. |
| `material` (rebuilds) | `data-dio-material` | `'paper' \| 'leather' \| 'metal' \| 'stone' \| 'plaster'` | `'paper'` | paper fibres; leather pebble grain; metal brushed; stone speckled; plaster troweled. |
| `depth` | `data-dio-depth` | `number` 0 to 0.15 em | `0.05` | Height or depth of the relief in ems of the font size; 0 is flat. |
| `bevel` | `data-dio-bevel` | `number` 0 to 0.1 em | `0.03` | Width of the sloped edge of each letter in ems; larger is softer and rounder. |
| `light` | `data-dio-light` | `number` 0 to 360° | `315` | Where the light comes from at rest as a CSS angle, 0 above and 90 right. |
| `follow` | `data-dio-follow` | `number` 0 to 1 | `1` | How far the light moves toward the pointer; 0 keeps it at its angle. |
| `grain` | `data-dio-grain` | `number` 0 to 2 | `1` | Strength of the material's own texture and mottle; 0 is smooth. |
| `color` (rebuilds) | `data-dio-color` | `string` | `''` | Ink or wax color, empty for the text color; given, it also inks emboss and deboss. |

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

### Variants

- `style`: `emboss`, `deboss`, `letterpress`, `stamp`
  - `emboss` raised.
  - `deboss` pressed in.
  - `letterpress` an inked impression.
  - `stamp` a wax seal.
- `material`: `paper`, `leather`, `metal`, `stone`, `plaster`
  - `paper` fibres.
  - `leather` pebble grain.
  - `metal` brushed.
  - `stone` speckled.
  - `plaster` troweled.

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`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 at a steady rate while it is on screen and stops when it leaves. None at rest: the relief is drawn once and stays. Full rate while the light settles after the pointer moves, and one frame per scroll while it drifts with the page. 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 light stays at its angle: it does not follow the pointer or drift with the scroll.

Runs on every device. The light drifts with the scroll; a finger does not move it, so a tap or a swipe never flickers the relief.

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

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

## Cost and quality

Loads 12.6 KB the first time a page uses it. GPU: One quad over the box; about twenty texture reads per pixel, sixteen of them for the shadow march toward the light. Memory: A half-float relief of the text built once on the CPU from a distance field, a 512 px tile of the material per page and a canvas of the text.

- low: The relief is built at 1 px per CSS px instead of 2, and the shadow takes 8 steps toward the light instead of 16.

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

## Recipes

### Five materials

`material` picks the surface: `paper` with soft fibres, `leather` with a pebble grain that darkens and polishes where it is pressed, brushed `metal` whose highlight stretches across the brushing, speckled `stone` and troweled `plaster`. Each one takes the background color of its element, so the same material comes in any color. Move the pointer along the row: the light is one lamp for all five.

A notebook shop's cover picker: five tiles in cotton paper, calf leather, brushed steel, slate and lime plaster, each with the initials JK pressed in or raised and the material named in small print.

```html title="index.html"
<div class="eb-covers">
  <p class="eb-ask">Your notebook, initialled J.K. Choose a cover:</p>
  <ul class="eb-row">
    <li class="eb-cotton" data-dio="emboss" data-dio-style="letterpress"><b>JK</b><span>Cotton paper</span></li>
    <li class="eb-calf" data-dio="emboss" data-dio-style="deboss" data-dio-material="leather"><b>JK</b><span>Calf leather</span></li>
    <li class="eb-steel" data-dio="emboss" data-dio-material="metal"><b>JK</b><span>Brushed steel</span></li>
    <li class="eb-slate" data-dio="emboss" data-dio-style="deboss" data-dio-material="stone"><b>JK</b><span>Slate</span></li>
    <li class="eb-lime" data-dio="emboss" data-dio-material="plaster"><b>JK</b><span>Lime plaster</span></li>
  </ul>
</div>
```

### A leather journal cover

`style="deboss"` presses the letters into the surface, with walls that fall into shadow on the side away from the light. Large text is blind, the way a cover is pressed without foil; text under 22 px is printed in its own color, because a blind relief that small cannot be read. Here the volume line is inked in the cover’s gold.

A product card for a leather notebook: a brown calf cover with Field Notes debossed in it, the price and a short description beside it.

```html title="index.html"
<div class="eb-shop">
  <div class="eb-book">
    <div class="eb-cover" data-dio="emboss" data-dio-style="deboss" data-dio-material="leather">
      <p class="eb-title">Field Notes</p>
      <p class="eb-no">Volume VII · 192 pages, dot grid</p>
    </div>
  </div>
  <div class="eb-copy">
    <p class="eb-price">£68</p>
    <p class="eb-text">Full-grain calf over boards, sewn by hand and pressed with your initials. Point at the cover to see the leather catch the light.</p>
  </div>
</div>
```

### A wax seal on an invitation

`style="stamp"` pours a pool of wax around the text, with a raised rim and the letters standing out of it, in the text color or `color`. The seal has no background of its own here, so it sits on the invitation’s paper; the shading of a relief without a background goes over whatever is behind it, a color, a gradient or a picture.

A wedding invitation on cream paper with the couple's initials in a dark red wax seal under the text.

```html title="index.html"
<div class="eb-invite">
  <p class="eb-line">Together with their families</p>
  <p class="eb-names">Rosa Marlowe and Milan Varga</p>
  <p class="eb-line">request the pleasure of your company on the twelfth of June</p>
  <span class="eb-seal" data-dio="emboss" data-dio-style="stamp">R &amp; M</span>
</div>
```

## Notes

The relief is built from the shape of the letters: a distance field of the text gives every pixel its distance to the nearest edge, and a profile over `bevel` turns that into a height. Raised letters get rounded shoulders, pressed letters steep walls and a flat floor, letterpress a shallower impression with bare paper walls, the ink lying flat in the bottom and the paper pushed up around it. The lighting runs per pixel: normals come from the relief and from a tile of the material’s own fine relief, and every pixel marches over the relief toward the lamp to find whether a letter stands between them, so shadows fall the right way and grow longer as the light gets lower.

The lamp sits about the size of the element away from it, at `light` when the pointer is elsewhere. It follows a mouse or a pen anywhere on the page and drifts as the element scrolls, as a lamp fixed in the room would. After it settles nothing more is drawn; the relief stays as it is. Set `follow` to 0 for a fixed light.

The element should be a card, a label or a heading with a background color: that color becomes the material, and the surface covers the box and its rounded corners. Its border, shadow and background image are not drawn, so put a box shadow on a wrapper, as the examples do. An element without a background is pressed into the page itself: its text gets the relief and shadows, and the page around it stays as it is.

The text stays real text in the DOM: screen readers read it, search engines index it, and find in page works. While the surface is drawn the element is hidden without being removed, so give the text a color that reads on the background, since that is what shows without WebGL. The canvas cannot draw `background-clip: text`, `-webkit-text-stroke` or vertical writing modes the way the browser does, and an element with any of them keeps its text as it is, with a warning in development.

`style`, `material` and `color` rebuild the effect when they change. `bevel` builds the relief again a moment after it changes; 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.
- [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.
- [inflate](/docs/effects/inflate.md): Letters puff up into round 3D shapes, like balloons or soft clay, that dent and wobble under the pointer.
- [Reduced motion](/docs/guides/reduced-motion.md)
- [Performance and quality](/docs/guides/performance.md)
