emboss
Letters pressed into or raised out of paper, leather, brushed metal, stone or plaster, lit by a light that follows the pointer.
Hollis & Vane
Bookbinding and restoration since 1932
Live preview needs WebGPU or WebGL 2. 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.
This example failed to draw.
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. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add emboss<div class="eb-desk"> <div class="eb-lift"> <div class="eb-card" data-dio="emboss"> <p class="eb-name">Hollis & 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>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.eb-card', 'emboss', { style: 'emboss', depth: 0.05, bevel: 0.03, light: 315, follow: 1, grain: 1,})import { start } from '@dioramajs/diorama'import emboss from '@dioramajs/text/emboss'
const app = start()app.attach('.eb-card', emboss({ style: 'emboss', depth: 0.05, bevel: 0.03, light: 315, follow: 1, grain: 1,}))Page transitions
The surface fades with the page. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'emboss' | 'deboss' | 'letterpress' | 'stamp' | 'emboss' |
|
materialrebuildsdata-dio-material | 'paper' | 'leather' | 'metal' | 'stone' | 'plaster' | 'paper' |
|
depthdata-dio-depth | number0 to 0.15 em | 0.05 | Height or depth of the relief in ems of the font size; 0 is flat. |
beveldata-dio-bevel | number0 to 0.1 em | 0.03 | Width of the sloped edge of each letter in ems; larger is softer and rounder. |
lightdata-dio-light | number0 to 360° | 315 | Where the light comes from at rest as a CSS angle, 0 above and 90 right. |
followdata-dio-follow | number0 to 1 | 1 | How far the light moves toward the pointer; 0 keeps it at its angle. |
graindata-dio-grain | number0 to 2 | 1 | Strength of the material's own texture and mottle; 0 is smooth. |
colorrebuildsdata-dio-color | string | '' | Ink or wax color, empty for the text color; given, it also inks emboss and deboss. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
It reads delta, height, reducedMotion, size, width, x and 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. How a frame is decided.
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.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { emboss: { reducedMotion: 'off' } } })Cost and quality
- Download
- 12.6 KB min+gzip 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.
- Frames
- Draws while on screen
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
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. |
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.
Your notebook, initialled J.K. Choose a cover:
- JKCotton paper
- JKCalf leather
- JKBrushed steel
- JKSlate
- JKLime plaster
Live preview needs WebGPU or WebGL 2. 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.
This example failed to draw.
<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.
Field Notes
Volume VII · 192 pages, dot grid
£68
Full-grain calf over boards, sewn by hand and pressed with your initials. Point at the cover to see the leather catch the light.
Live preview needs WebGPU or WebGL 2. 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.
This example failed to draw.
<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.
Together with their families
Rosa Marlowe and Milan Varga
request the pleasure of your company on the twelfth of June
R & MLive preview needs WebGPU or WebGL 2. A wedding invitation on cream paper with the couple's initials in a dark red wax seal under the text.
This example failed to draw.
<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 & 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.