Make a CSS box shadow
Set how far each shadow falls, how soft it is, and its colour, and stack as many layers as you need. Switch between a box, a line of text, and a picture to get box-shadow, text-shadow, or a drop-shadow() filter, and paste a shadow from your own stylesheet to keep editing it.
Preview only, not in the CSS
How to use it#
- Choose Box, Text, or Picture above the preview.
- Pick a layer in the list and set how far it falls across and down, its blur, spread, colour, and opacity. For a box, Inset puts the shadow inside it. Add layer puts a new one under the selected layer, and Undo steps back through your changes.
- Change the background, colour, and corners of the preview to match your page, then copy the CSS, or paste an existing shadow into the CSS box to edit it.
Box, text, or picture#
box-shadow follows the box: its rectangle, rounded by any border-radius. It ignores what is inside, so a PNG with a transparent background gets a shadow around its square, not around the shape in it. text-shadow follows the letters of the text instead, and takes the same lengths and colour, without spread or inset.
filter: drop-shadow() follows whatever is drawn, transparent parts left out, so it is the one to use for a cut-out photo, an SVG icon, or a logo. Like a text shadow it has no spread or inset. A filter takes one shadow in each drop-shadow() call, so this page writes one call per layer. Each call shadows everything before it, the earlier shadows included, so two layers come out darker than the same two as a box-shadow.
What each number does#
Across and Down move the shadow away from the box in pixels; negative values move it left and up. A light from above casts a shadow down, so most interfaces keep Across at 0 and give Down a few pixels.
Blur softens the edge. The browser blurs the shadow over a band about twice the blur value wide, centred on where the hard edge would be, so a 10px blur fades from 10px inside the edge to 10px outside it. A blur of 0 gives a hard-edged copy of the box.
Spread grows the shadow on every side before it is blurred, and a negative spread shrinks it. A negative spread with a downward offset hides the shadow at the box's sides and keeps it underneath, which is how a card looks lifted without a grey halo. Inset draws the shadow inside the box's edge, as if the box were pressed into the page.
Layers and natural-looking shadows#
A box-shadow can hold any number of shadows, separated by commas, and the first one in the list is drawn on top. A real shadow is dark and sharp close to the object and lighter and wider further away, so two or three layers look more natural than one: a small, tight shadow near the box and a wide, faint one around it. The page starts with two such layers.
Keep the opacity low, often 5% to 20% black. Several faint layers stacked together look softer than one dark one. A shadow tinted with a darker shade of the background, rather than plain black, looks less muddy on a coloured page. On a dark page a shadow barely shows at all, so dark designs often lift a card with a lighter surface or a thin border instead.
Pasting a shadow to edit it#
The CSS box reads a box-shadow, text-shadow, or filter declaration, with -webkit- prefixes or !important, and a value pasted on its own too. The colour and inset can come before or after the lengths. A pasted value with inset or a fourth length is a box shadow, and drop-shadow() is a picture shadow, so the page switches to match.
The page works in pixels, so lengths in em or rem are refused with a message: at the usual 16px root size, 1rem is 16px. A shadow with no colour takes the text colour, which the page cannot see, so it loads as black and the page says so. A filter holding anything besides drop-shadow(), such as blur(), is refused, so copy the shadows and add the rest back.
Frequently asked questions#
How do I put a shadow only under a box?
#
Give it a downward offset and a negative spread as large as the blur, such as 0 8px 6px -6px. The spread pulls the shadow in by 6px on every side and the blur spreads it back out by about 6px, so the sides end at the box's edge, and the 8px offset shows it below. For a shadow only on the right, swap the offset across: 8px 0 6px -6px.
Why does box-shadow ignore my PNG's transparent background?
#
box-shadow is drawn around the element's box, which for an image is its whole rectangle, transparent pixels included. Choose Picture to write filter: drop-shadow() instead, which follows the shape that is drawn. It works on an img, an inline SVG, or any element, and the shadow wraps around text and children too.
Does a box shadow take up space or slow the page down?
#
Neither, in most cases. A shadow takes no room in the layout and does not move anything around it, though a parent with overflow: hidden cuts it off at the parent's edge, so leave room or move the overflow. A large blur is cheap to draw once but costly to animate, so to make a shadow appear on hover, put it on a pseudo-element and fade that element's opacity rather than changing the shadow itself.
How do I make text readable over a photo with text-shadow?
#
Use a soft dark shadow close to the letters, such as 0 1px 3px at 60% black, and a second wider one, such as 0 0 12px at 40%, for busy parts of the photo. It helps light text on a mostly light picture, but it cannot rescue every photo: for long text, a dark gradient over the bottom of the image is more reliable. The CSS gradient generator makes one.
Can I use rem or em in a box shadow?
#
CSS accepts them, and a shadow in em grows with the font size, which suits a button whose text size changes. This page edits in pixels, so convert before pasting: multiply by 16 for rem at the default root size, or by the element's font size for em. The copied CSS is in pixels, and you can change it back by hand.