CSS text-shadow: Syntax, Layer Order and Readable Shadows
Last updated: · 6 min read
text-shadow paints one or more shadows behind the glyphs of a piece of text. It is a single declaration, yet working out by hand how its four values (horizontal offset, vertical offset, blur and colour) play together means a lot of editing and reloading. The CSS Text-Shadow Generator puts those values on sliders, stacks up to six layers and writes the declaration that produces what you see in the preview. This guide covers the rules from the W3C definition of the property, the order in which layers are painted and when a shadow helps legibility or harms it. Every snippet in the example is real output from the tool.
Formula
text-shadow: <offset-x> <offset-y> <blur-radius> <color> text-shadow: <layer 1>, <layer 2>, … (the first layer is painted on top) What the generator writes for each layer: Xpx Ypx Bpx rgba(R, G, B, A)
The first two lengths move the shadow relative to the text: a positive horizontal value pushes it right, a positive vertical value pushes it down. The third length is the blur radius; 0 gives a hard edge and negative values are not allowed. Browsers soften the shadow so that it approximates a Gaussian blur whose standard deviation is half that radius. If no colour is given, the text's own colour is used; the tool always writes the colour as rgba(), with the opacity slider setting the last component. Unlike box-shadow, text-shadow has no spread value and no inset keyword. A shadow does not affect layout, takes up no space and does not enlarge the scrollable area.
What the inputs mean
- Horizontal and Vertical
- The offset of the shadow, from −50 to 50 px. With both at 0 the shadow sits directly behind the text and only shows as far as the blur reaches, which is how a glow is made.
- Blur
- 0–60 px. A value of 0 gives a crisp, print-like shadow; larger values spread the shadow out and make it fainter.
- Opacity and colour
- The colour is picked as hex and the opacity set between 0 and 100 %; the code combines them into one rgba() value. 40 % opacity is written as 0.4.
- + Add shadow / Remove
- Up to six layers; at least one always remains. The layer at the top of the list comes first in the code and is painted over the others.
- Preview settings
- Preview text, font size (12–120 px), text colour and background colour only change the preview and are not part of the generated code. Use them to try the shadow against your own colours.
Worked example: A soft two-layer shadow for a heading on a photo
- The tool opens with one layer: Horizontal 2, Vertical 2, Blur 4, colour #0f172a, Opacity 40 %. Generated code: text-shadow: 2px 2px 4px rgba(15, 23, 42, 0.4);
- Turn the first layer into a tight contact shadow: Horizontal 0, Vertical 1, Blur 2, colour #000000, Opacity 60 %. This layer separates the edge of each letter from the background.
- Press “+ Add shadow”. The new layer starts at Horizontal −2, Vertical −2, Blur 4, #4f46e5, 50 %; change it to Horizontal 0, Vertical 4, Blur 12, colour #000000, Opacity 35 %. This wide layer forms a dark halo around the letters.
- The tool writes both layers separated by a comma: text-shadow: 0px 1px 2px rgba(0, 0, 0, 0.6), 0px 4px 12px rgba(0, 0, 0, 0.35);
- The tight shadow, written first, is painted on top and the wide one beneath it. In the opposite order the wide, faint layer would cover the tight one.
- For comparison, a hard shadow: keep a single layer and choose Horizontal 3, Vertical 3, Blur 0, colour #4f46e5, Opacity 100 %. Code: text-shadow: 3px 3px 0px rgba(79, 70, 229, 1);
Result: The two-layer version (0px 1px 2px plus 0px 4px 12px) lifts a light heading off a busy photo, while the single hard layer is a decorative, poster-style effect.
How to read the result
Shadows serve two purposes: supporting legibility and decoration. On light text over an image, a dark blurred shadow darkens the area around each letter and does help, but the dependable way to secure contrast is still a semi-transparent dark overlay on the image. On body copy a shadow mostly makes letters fuzzy, so keep it to headings. For a glow, set both offsets to zero and use one colour at two blur sizes; the tool produces, for example: text-shadow: 0px 0px 6px rgba(34, 211, 238, 0.9), 0px 0px 20px rgba(34, 211, 238, 0.6); A dark shadow disappears on a dark background, so in a dark theme drop it or swap it for a light glow. Large blur radii on long passages or in animations raise the painting cost.
Common mistakes
- Adding a fourth length (spread) or inset out of box-shadow habit. text-shadow accepts neither; the declaration becomes invalid and is ignored entirely.
- Getting the layer order backwards. The first shadow listed is on top, so put the tight, sharp layer first and the wide, faint one last.
- Trying to rescue low-contrast text with a shadow. A shadow on light grey text over a light grey background just smudges the letters; fix the text and background colours first.
- Using pure black at 100 % opacity with a large blur. It leaves a dirty blotch around the text; lowering the opacity or picking a dark tone of the background looks cleaner.
- Forgetting that the shadow shows through semi-transparent text. Shadows are not clipped to the shape of the glyphs, so with a translucent text colour the shadow behind is visible too.
- Assuming the preview's text and background colours are part of the code. The tool only outputs the text-shadow line; color and background have to be set in your own styles.
Frequently asked questions
What is the order of values in text-shadow?
Two or three lengths in a row: horizontal offset, vertical offset and an optional blur radius. The colour may come before or after the lengths; the tool writes it last.
How do I add multiple text shadows, and which one is on top?
Separate the layers with commas. The first one is painted on top; shadows may overlap each other but are never painted over the text itself.
Does text-shadow support spread or inset?
No. Both belong to box-shadow. To thicken a text shadow, stack several layers of the same colour with small offsets.
Does text-shadow change layout or line height?
No. A shadow takes up no space, does not push neighbouring elements and does not extend the scrollable area; it is only painted.
Can I outline text with text-shadow?
Four layers with a blur of 0, shifted 1 px in each direction, give the impression of a thin outline. Gaps appear at the corners as the width grows, so the technique suits thin outlines only.
Why does the tool write the shadow as rgba()?
To combine colour and opacity in one value. #0f172a at 40 % becomes rgba(15, 23, 42, 0.4), so the shadow blends with whatever lies beneath and looks natural on different backgrounds.
The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.