CSS Box Shadow: How Blur, Spread and Layers Work
CSS box shadow explained: offsets, blur, spread, inset and layers, plus text-shadow and drop-shadow. Blur follows a Gaussian model; drop-shadow differs.
By TheTextKit TeamPublished

A table of three results for the CSS shadow generator. 400 random shadows of every kind were checked in Chromium. 324,001 pixels of box shadows with whole pixel offsets were compared with a Gaussian model. The mean difference was 0.02 levels of colour out of 255.
A CSS box shadow is a blurred copy of an element's box, moved by an offset and drawn behind it. You write it as box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.25);, which means no horizontal offset, 4 pixels down, a 12 pixel blur, no spread and a quarter-strength black. This guide explains each value, what the blur actually does to the pixels, how layers and inset work, and the one way that drop-shadow() counts blur differently. We also checked our CSS shadow generator against Chromium on 400 shadows.
CSS box shadow syntax
According to MDN, a box shadow takes two, three or four lengths, an optional inset keyword and an optional colour. The first two lengths are the offsets and are required. The third is the blur, and the fourth is the spread.
| Value | What it does |
|---|---|
| Horizontal offset | Moves the shadow right, or left when negative |
| Vertical offset | Moves the shadow down, or up when negative |
| Blur | Softens the edge, 0 is sharp |
| Spread | Grows the shadow, or shrinks it when negative |

A table of the four lengths of a box shadow. The horizontal offset moves the shadow right. The vertical offset moves it down. The blur softens the edge. The spread grows or shrinks the shadow.
The CSS Shadow Generator writes the line for you from sliders. One point from MDN is worth remembering: a box shadow does not impact the dimensions of the box, so it can't push other elements around. It can be covered by a neighbour, or cut off by a parent that hides overflow. That's easy to forget until a shadow vanishes at the edge of a card.
What blur really does
The blur is not a width in pixels of a soft border. The CSS Backgrounds specification says the shadow must approximate a Gaussian blur with a standard deviation equal to half the blur radius. So a 12px blur is a Gaussian with a standard deviation of 6px. The specification leaves the exact algorithm open, but requires each pixel to be within 5% of its expected value, which is about 12.75 levels out of 255.
A Gaussian blur has a handy property: at the nominal edge of the shadow, the strength is exactly half. So the shadow fades across a band roughly as wide as the blur radius on each side of that edge, and a larger blur just widens the band.
We tested this in Chromium. We made 194 box shadows with random blur, spread and opacity and whole pixel offsets. Each was a black shadow behind a transparent box. We compared 324,001 pixels outside the box with a Gaussian calculation from the formula above.
| Measure | Result |
|---|---|
| Shadows drawn | 194 |
| Pixels compared | 324,001 |
| Mean difference | 0.02 levels of 255 |
| 99% of pixels within | 0.7 levels |
| Largest difference | 12.4 levels |

A table of how closely Chromium's box shadows match a Gaussian blur with a standard deviation of half the blur radius. The mean difference was 0.02 levels of 255. 99% of pixels were within 0.7 levels. The largest difference was 12.4 levels.
The mean is tiny, and even the largest difference, 12.4, is inside the 12.75 the specification allows. The few large ones came from a blur under 1px, where the edge is almost sharp and a tiny difference in position shows.
Spread, offsets and soft shadows
MDN says a positive spread causes the shadow to expand and a negative spread causes it to shrink. Spread is applied before the blur. That is the trick behind the soft, lifted shadows you see on cards: a large vertical offset and blur with a negative spread, such as 0px 20px 25px -5px. The shadow is pulled in from the sides so that it appears only below the box.
One surprise comes up with fractional values. In our first run, with offsets such as 25.82px and a small blur, a few sharp edges differed from the model by more than 100 levels in a single pixel. With whole pixel offsets this did not happen. If you need exact edges, use whole pixels.
Several shadows and inset
You can give a list of shadows, separated by commas. The specification says the shadows are applied front to back, so the first shadow is on top. A small, sharp shadow on top of a large, faint one looks more like real light than a single blurred shadow does.
The inset keyword turns a shadow into one drawn inside the box. MDN says inset shadows are clipped to the padding box and appear above the background but below the content, which is why they suit pressed buttons and text fields.
text-shadow and drop-shadow
Two other properties use the same idea. A text-shadow takes two or three lengths and a colour, with the offsets, an optional blur and no spread. According to MDN, several text shadows are applied front to back too, with the first on top.
The drop-shadow() filter follows the shape of what is drawn. MDN says that box-shadow creates a rectangular shadow behind an element's entire box, while drop-shadow() creates a shadow that conforms to the shape, the alpha channel, of the image itself. That makes it the right tool for a transparent PNG or an irregular icon. It does not accept spread or inset.
| Property | Follows | Spread | Inset |
|---|---|---|---|
| box-shadow | The element's box | Yes | Yes |
| text-shadow | The letters | No | No |
| drop-shadow() | The drawn shape | No | No |

A table comparing three shadow properties. The box-shadow property follows the element's box and supports spread and inset. The text-shadow property follows the letters and has neither. The drop-shadow filter follows the drawn shape and has neither.
There is one trap. MDN says the blur value of drop-shadow() is interpreted as a standard deviation. That is the number the specification halves for a box shadow. So the same number gives a much softer drop shadow. We put a box shadow and a drop shadow on the same opaque box and compared every pixel.
| Blur written | Same number in drop-shadow, largest difference | Half the number, largest difference |
|---|---|---|
| 4px | 38 levels | 3 levels |
| 12px | 30 levels | 5 levels |
| 20px | 26 levels | 0 levels |
| 30px | 23 levels | 0 levels |

A table comparing the blur of drop-shadow with box-shadow in Chromium. Using the same number differed by up to 38 levels of colour for a 4px blur and 23 for a 30px blur. Using half the number differed by 3, 5, 0 and 0 levels.
So a box shadow with a 12px blur matches a drop shadow with a 6px blur. Our generator warns you in drop shadow mode, and writes the number you enter.
How we tested the generator
The generator builds strings, so the checks ask whether a browser reads them as we meant. A script made 400 random shadows of all three kinds, with one to three layers, random offsets up to 30px either way, blur, spread, opacity, colours and the inset keyword. For each one we set the value in Chromium and read the computed style back. The numbers, colour and inset flag matched in all 400, so no value was dropped or changed.
The pixel comparison is the one in the table above. We also checked that every preset is valid, and that blur below zero, offsets beyond 1,000px, bad colours and more than six shadows are refused.
Limits
The pixel checks ran in Chromium only, and with a black shadow behind a transparent box. Other browsers may differ in how they round, within the 5% the specification allows. The tool writes hex colours with a separate opacity, and does not write the older vendor prefixed versions of these properties.
Frequently asked questions
How do I make a CSS box shadow?
A box shadow is set with the box-shadow property on the element. It takes four lengths: the horizontal offset, the vertical offset, the blur and the spread, followed by the colour. A generator builds the line and shows a preview.
What is the difference between blur and spread?
Blur softens the edge of the shadow. Spread makes the shadow bigger or smaller before it is blurred: a positive spread grows it on every side and a negative spread shrinks it. Soft shadows that sit tightly under a box often use a negative spread.
Why does my drop-shadow look blurrier than my box-shadow?
Because the blur number means something different. In a box shadow it is a blur radius, and the blur is a Gaussian with a standard deviation of half that. In drop-shadow the number is the standard deviation itself, so use half the number to get the same look.
How do I add several shadows?
Write a comma separated list, and the first shadow is drawn on top. Stacking a small sharp shadow with a large soft one gives a more natural look than a single shadow does. The generator can stack up to six.
Does a box shadow change the size of the element?
No. MDN says a box shadow does not affect the dimensions of the box, so it can't push other elements around. It can be covered by neighbours, or cut off by a parent that hides overflow.
Build your shadow now
Open the CSS Shadow Generator to design a CSS box shadow with a live preview and copy the CSS. For the background behind it, use the CSS Gradient Generator, and for converting colours, the Color Converter. Everything runs in your browser, so nothing you design is uploaded.


