Text
Wrap a word or a heading in <sd-text> and it becomes a solid: extruded letters in your own font, drawn exactly over the HTML, which stays in the page for layout and screen readers.
Add the script once, then use the tags anywhere.
<script type="module" src="https://mmaxence.github.io/solids/solids.js"></script>
Or copy the library into your project: download solids.js from the repo and serve it yourself. No build step, no other files.
How text works
The element reads the text it wraps and the computed CSS font of that element, rasterizes the line on a canvas, turns the raster into a signed distance field and uploads it as a texture. The shader extrudes that field with a rounded edge and marches it like any object, so the letters take every shade, effect and animation, and every interaction moves them. Tap a letter with poke and the word turns to show its sides. With pixel the raster is sampled at that cell size, which gives a pixel font from any monospace; the distance field keeps the blocks sharp.
On a light background the word reads through its shade like any object: auto is glass in the dark theme and matte in the light one, with a darker edge; no effect is needed.
Options
| Attribute | Type | Default | Range | Description |
|---|---|---|---|---|
depth | number | 0.35 | 0.02 to 1 | Half the thickness of the extrusion. |
bevel | number | 0.25 | 0 to 1 | Rounding of the edges. |
pixel | number | 0 | 0 to 24 | Raster cell in px for a pixel-font look from any monospace; 0 keeps the glyphs smooth. |
color | color | #9bd1ff | any CSS color, including color(display-p3 r g b) | Accent color of the object. |
animation | list | none | idle, spin, pulse, breathe, float | Space separated animations, composed in order. |
speed | number | 1 | 0.1 to 3 | Multiplies animation time. |
state | keyword | idle | off, idle, busy, active | Brightness level, eased on change. |
effect | list | none | glow, beam, rgb-split, pixelate, dither, scanlines, halftone, outline, grain, vignette, chroma, ripple, defocus | Space separated post effects on this object only. |
shading | keyword | auto | auto, glass, matte, cel, clay, metal | How the surface takes light. auto is glass in the dark theme and matte in the light one; a scene's shading is the default for its children. |
gravity | keyword | orbit | center, orbit, fall, none | Role in a gravity scene. |
License
MIT. Use it anywhere, credit appreciated.