text-shadow is usually reached for when you want a soft, blurred glow behind text. But like box-shadow, the blur amount is yours to control, and it can be driven all the way to zero. Sharp-offset shadows, comma-separated and stacked on a single element, are enough to build lettering that reads as three-dimensional.

The property, briefly
.el {
text-shadow: [x-offset] [y-offset] [blur] [color];
}
x-offset— horizontal position. Positive pushes the shadow right, negative pushes it left. (required)y-offset— vertical position. Positive pushes the shadow down, negative pushes it up. (required)blur— softness. Higher values blur more; the default is0px, meaning no blur. (optional)color— the shadow's color. (required)
Building up the stack
A single shadow already gives text some presence; push it 6px right and 6px down and it sits firmly beneath the letterforms:
:root {
--text: #5362F6; /* Blue */
--shadow: #E485F8; /* Pink */
}
.playful {
color: var(--text);
text-shadow: 6px 6px var(--shadow);
}

That is still a flat slab, though, with no visible depth connecting the shadow to the text. Additional text-shadow instances on the same element, separated by commas, close the gap. Start with one extra entry in the middle:
.playful {
color: var(--text);
text-shadow: 6px 6px var(--shadow),
3px 3px var(--shadow);
}

More steps produce a finer result. The example works downward from 6px 6px in 0.25px increments until it reaches 0:
.playful {
color: var(--text);
text-shadow:
6px 6px var(--shadow),
5.75px 5.75px var(--shadow),
5.5px 5.5px var(--shadow),
5.25px 5.25px var(--shadow),
5px 5px var(--shadow),
4.75px 4.75px var(--shadow),
4.5px 4.5px var(--shadow),
4.25px 4.25px var(--shadow),
4px 4px var(--shadow),
3.75px 3.75px var(--shadow),
3.5px 3.5px var(--shadow),
3.25px 3.25px var(--shadow),
3px 3px var(--shadow),
2.75px 2.75px var(--shadow),
2.5px 2.5px var(--shadow),
2.25px 2.25px var(--shadow),
2px 2px var(--shadow),
1.75px 1.75px var(--shadow),
1.5px 1.5px var(--shadow),
1.25px 1.25px var(--shadow),
1px 1px var(--shadow),
0.75px 0.75px var(--shadow),
0.5px 0.5px var(--shadow),
0.25px 0.25px var(--shadow);
}
Generating the shadows with Sass
Hand-written, that list is hard to read and worse to maintain — resizing the shadow to 10px would mean adding 16 more entries by hand. An SCSS function can generate them instead:
@function textShadow($precision, $size, $color){
$value: null;
$offset: 0;
$length: $size * (1 / $precision) - 1;
@for $i from 0 through $length {
$offset: $offset + $precision;
$shadow: $offset + px $offset + px $color;
$value: append($value, $shadow, comma);
}
@return $value;
}
.playful {
color: #5362F6;
text-shadow: textShadow(0.25, 6, #E485F8);
}
textShadow takes three arguments: precision, size and color. It loops, increasing the offset by $precision (0.25px here) until it reaches the full size (6px here). Resizing or refining the effect then becomes a one-line change:
text-shadow: textShadow(0.1, 10, #E485F8);
Alternating colors per letter
To vary colors, split the text into individual letters wrapped in span elements — done by hand, or automated with React or JavaScript. The markup output looks like this:
<p class="playful" aria-label="Wash your hands!">
<span aria-hidden="true">W</span><span aria-hidden="true">a</span><span aria-hidden="true">s</span><span aria-hidden="true">h</span> ...
</p>
From there, :nth-child() on the spans alters both the text color and its shadow:
.playful span:nth-child(2n) {
color: #ED625C;
text-shadow: textShadow(0.25, 6, #F2A063);
}
The equivalent in plain CSS:
.playful span {
color: var(--text);
text-shadow:
6px 6px var(--shadow),
5.75px 5.75px var(--shadow),
5.5px 5.5px var(--shadow),
5.25px 5.25px var(--shadow),
5px 5px var(--shadow),
4.75px 4.75px var(--shadow),
4.5px 4.5px var(--shadow),
4.25px 4.25px var(--shadow),
4px 4px var(--shadow),
3.75px 3.75px var(--shadow),
3.5px 3.5px var(--shadow),
3.25px 3.25px var(--shadow),
3px 3px var(--shadow),
2.75px 2.75px var(--shadow),
2.5px 2.5px var(--shadow),
2.25px 2.25px var(--shadow),
2px 2px var(--shadow),
1.75px 1.75px var(--shadow),
1.5px 1.5px var(--shadow),
1.25px 1.25px var(--shadow),
1px 1px var(--shadow),
0.75px 0.75px var(--shadow),
0.5px 0.5px var(--shadow),
0.25px 0.25px var(--shadow);
}
.playful span:nth-child(2n) {
--text: #ED625C;
--shadow: #F2A063;
}
Repeating this with other colors and index values lets you settle on a pattern you like.
Animating the letters
The same stacking approach extends to motion. Begin with a looping animation that nudges each span up and down:
.playful span {
color: #5362F6;
text-shadow: textShadow(0.25, 6, #E485F8);
position: relative;
animation: scatter 1.75s infinite;
}
Wrap it in a prefers-reduced-motion media query so it is skipped by anyone who has asked not to receive animation:
.playful span {
color: #5362F6;
text-shadow: textShadow(0.25, 6, #E485F8);
position: relative;
animation: scatter 1.75s infinite;
}
@media screen and (prefers-reduced-motion: reduce) {
animation: none;
}
Finally, give each nth-child(n) a different animation delay:
.playful span:nth-child(2n) {
color: #ED625C;
text-shadow: textShadow(0.25, 6, #F2A063);
animation-delay: 0.3s;
}


