How it works
A shadow made of many shadows
CSS has no extrude property. But text-shadow takes a list, and a few dozen hard-edged copies of the text, each nudged a little further along the same direction, merge into one solid shape: a long shadow, or the side walls of 3D letters.
1. Copies along an angle
Every entry in a text-shadow list is a full copy of the glyphs at an offset,
with a blur radius and a color. With a blur of 0 the copy has hard edges. Place copy number i of n at (cos θ, sin θ) × length × i / n and the copies overlap into a continuous band from
the letters to the end of the shadow. The angle is in screen coordinates: 0° points right, 90°
down.
The list is generated by a small pure function, so the CSS stays a plain value and the component has no runtime cost beyond painting:
function longShadow({ angle, length, steps, from, to }) {
const rad = (angle * Math.PI) / 180;
return Array.from({ length: steps }, (_, k) => {
const d = (length * (k + 1)) / steps; // em along the angle
const t = steps > 1 ? k / (steps - 1) : 0; // 0 at the letters, 1 at the end
const x = (Math.cos(rad) * d).toFixed(4);
const y = (Math.sin(rad) * d).toFixed(4);
const color = `color-mix(in oklab, ${from}, ${to} ${t * 100}%)`;
return `${x}em ${y}em 0 ${color}`;
}).join(', ');
} Shadows are painted back to front from the end of the list, so the first entry, the one closest to the letters, ends up on top. That's the right order for an extrusion: near walls cover far ones.
2. Steps and gaps
The copies only merge if each step is short. Above roughly one and a half pixels the letter
edges of neighboring copies stop overlapping in thin strokes and diagonals, and the shadow
turns into a stack of visible outlines. The panel shows the step size at the stage's font
size. Since length is in em, the same settings get coarser on bigger text.
The step count is capped at 60. Each step is one more full copy of the text to rasterize, and past a few dozen they mostly paint over each other. For a really long shadow on very large type, a blurred end (Fade out) hides the gaps better than more steps.
3. Color ramp: color-mix()
Each step's color is color-mix(in oklab, start, end p%) with p growing from 0
to 100 along the shadow; the browser does the mixing. oklab gives even
lightness steps, which reads as light falling off along the extrusion. srgb matches a classic CSS gradient and goes muddy between complementary colors; oklch keeps the saturation up but walks around the hue wheel. With Fade out each step is also mixed with transparent, so the shadow
dissolves into whatever is behind it.
.headline {
color: #fff4e0;
text-shadow:
0.0047em 0.0047em 0 #e0475b,
0.0094em 0.0094em 0 color-mix(in oklab, #e0475b, #4a1d5e 1.6949%),
0.0141em 0.0141em 0 color-mix(in oklab, #e0475b, #4a1d5e 3.3898%),
0.0189em 0.0189em 0 color-mix(in oklab, #e0475b, #4a1d5e 5.0847%),
0.0236em 0.0236em 0 color-mix(in oklab, #e0475b, #4a1d5e 6.7797%),
0.0283em 0.0283em 0 color-mix(in oklab, #e0475b, #4a1d5e 8.4746%),
0.033em 0.033em 0 color-mix(in oklab, #e0475b, #4a1d5e 10.1695%),
0.0377em 0.0377em 0 color-mix(in oklab, #e0475b, #4a1d5e 11.8644%),
0.0424em 0.0424em 0 color-mix(in oklab, #e0475b, #4a1d5e 13.5593%),
0.0471em 0.0471em 0 color-mix(in oklab, #e0475b, #4a1d5e 15.2542%),
0.0519em 0.0519em 0 color-mix(in oklab, #e0475b, #4a1d5e 16.9492%),
0.0566em 0.0566em 0 color-mix(in oklab, #e0475b, #4a1d5e 18.6441%),
0.0613em 0.0613em 0 color-mix(in oklab, #e0475b, #4a1d5e 20.339%),
0.066em 0.066em 0 color-mix(in oklab, #e0475b, #4a1d5e 22.0339%),
0.0707em 0.0707em 0 color-mix(in oklab, #e0475b, #4a1d5e 23.7288%),
0.0754em 0.0754em 0 color-mix(in oklab, #e0475b, #4a1d5e 25.4237%),
0.0801em 0.0801em 0 color-mix(in oklab, #e0475b, #4a1d5e 27.1186%),
0.0849em 0.0849em 0 color-mix(in oklab, #e0475b, #4a1d5e 28.8136%),
0.0896em 0.0896em 0 color-mix(in oklab, #e0475b, #4a1d5e 30.5085%),
0.0943em 0.0943em 0 color-mix(in oklab, #e0475b, #4a1d5e 32.2034%),
0.099em 0.099em 0 color-mix(in oklab, #e0475b, #4a1d5e 33.8983%),
0.1037em 0.1037em 0 color-mix(in oklab, #e0475b, #4a1d5e 35.5932%),
0.1084em 0.1084em 0 color-mix(in oklab, #e0475b, #4a1d5e 37.2881%),
0.1131em 0.1131em 0 color-mix(in oklab, #e0475b, #4a1d5e 38.9831%),
0.1179em 0.1179em 0 color-mix(in oklab, #e0475b, #4a1d5e 40.678%),
0.1226em 0.1226em 0 color-mix(in oklab, #e0475b, #4a1d5e 42.3729%),
0.1273em 0.1273em 0 color-mix(in oklab, #e0475b, #4a1d5e 44.0678%),
0.132em 0.132em 0 color-mix(in oklab, #e0475b, #4a1d5e 45.7627%),
0.1367em 0.1367em 0 color-mix(in oklab, #e0475b, #4a1d5e 47.4576%),
0.1414em 0.1414em 0 color-mix(in oklab, #e0475b, #4a1d5e 49.1525%),
0.1461em 0.1461em 0 color-mix(in oklab, #e0475b, #4a1d5e 50.8475%),
0.1508em 0.1508em 0 color-mix(in oklab, #e0475b, #4a1d5e 52.5424%),
0.1556em 0.1556em 0 color-mix(in oklab, #e0475b, #4a1d5e 54.2373%),
0.1603em 0.1603em 0 color-mix(in oklab, #e0475b, #4a1d5e 55.9322%),
0.165em 0.165em 0 color-mix(in oklab, #e0475b, #4a1d5e 57.6271%),
0.1697em 0.1697em 0 color-mix(in oklab, #e0475b, #4a1d5e 59.322%),
0.1744em 0.1744em 0 color-mix(in oklab, #e0475b, #4a1d5e 61.0169%),
0.1791em 0.1791em 0 color-mix(in oklab, #e0475b, #4a1d5e 62.7119%),
0.1838em 0.1838em 0 color-mix(in oklab, #e0475b, #4a1d5e 64.4068%),
0.1886em 0.1886em 0 color-mix(in oklab, #e0475b, #4a1d5e 66.1017%),
0.1933em 0.1933em 0 color-mix(in oklab, #e0475b, #4a1d5e 67.7966%),
0.198em 0.198em 0 color-mix(in oklab, #e0475b, #4a1d5e 69.4915%),
0.2027em 0.2027em 0 color-mix(in oklab, #e0475b, #4a1d5e 71.1864%),
0.2074em 0.2074em 0 color-mix(in oklab, #e0475b, #4a1d5e 72.8814%),
0.2121em 0.2121em 0 color-mix(in oklab, #e0475b, #4a1d5e 74.5763%),
0.2168em 0.2168em 0 color-mix(in oklab, #e0475b, #4a1d5e 76.2712%),
0.2216em 0.2216em 0 color-mix(in oklab, #e0475b, #4a1d5e 77.9661%),
0.2263em 0.2263em 0 color-mix(in oklab, #e0475b, #4a1d5e 79.661%),
0.231em 0.231em 0 color-mix(in oklab, #e0475b, #4a1d5e 81.3559%),
0.2357em 0.2357em 0 color-mix(in oklab, #e0475b, #4a1d5e 83.0508%),
0.2404em 0.2404em 0 color-mix(in oklab, #e0475b, #4a1d5e 84.7458%),
0.2451em 0.2451em 0 color-mix(in oklab, #e0475b, #4a1d5e 86.4407%),
0.2498em 0.2498em 0 color-mix(in oklab, #e0475b, #4a1d5e 88.1356%),
0.2546em 0.2546em 0 color-mix(in oklab, #e0475b, #4a1d5e 89.8305%),
0.2593em 0.2593em 0 color-mix(in oklab, #e0475b, #4a1d5e 91.5254%),
0.264em 0.264em 0 color-mix(in oklab, #e0475b, #4a1d5e 93.2203%),
0.2687em 0.2687em 0 color-mix(in oklab, #e0475b, #4a1d5e 94.9153%),
0.2734em 0.2734em 0 color-mix(in oklab, #e0475b, #4a1d5e 96.6102%),
0.2781em 0.2781em 0 color-mix(in oklab, #e0475b, #4a1d5e 98.3051%),
0.2828em 0.2828em 0 #4a1d5e;
} 4. Long shadow or extrusion
The same list makes both looks; only the numbers change:
- Long shadow
- Long (0.5em and more), one flat color or a fade, usually at 45°. The flat-design look: as if the letters stood on the page in low sunlight.
- Extrusion
- Short (0.1 to 0.2em) with a ramp from a darker shade of the text color to a much darker one: the side walls of solid letters. Ambient shadow adds one blurred shadow beyond the last step, so the block sits on the page instead of floating.
Accessibility
The text is a single real text node; the shadows are paint only, so selection, search and screen readers see plain text. Legibility depends on the edge: where the letters touch the shadow, the text color has to stand out from the shadow start color, and elsewhere from the page. The panel shows both ratios; at least one of them should reach 3:1 for large text. In forced-colors mode the shadow is removed.
Browser support and performance
text-shadow is Baseline widely available since 2015, and color-mix() is Baseline widely available too. Checked in Chromium and Firefox; Safari
is untested.
- Static, the shadows are painted once and cached. Changing them (dragging a slider) repaints all copies; that's the only time they cost anything.
- Animating the angle or length on large text repaints dozens of glyph copies per frame. Keep that to small text or a few steps.
- Hard-edged shadows (blur 0) are much cheaper than blurred ones; only the optional ambient shadow is blurred.