CSS Box Shadow Explained: Syntax, Examples and Soft Shadows That Look Real

Illustration: three white cards on a pale blue background showing a soft shadow, a lifted shadow and a hard retro shadow, with the CSS box-shadow syntax above them
Original illustration by ViralScopeHub

Short answer

The CSS box-shadow property takes up to five values: a horizontal offset, a vertical offset, a blur radius, a spread radius and a colour, with the optional word inset to put the shadow inside the box. For example, box-shadow: 0 4px 14px rgba(15, 23, 42, 0.08); gives a soft card shadow. The quickest way to get one that looks right is to drag the sliders in our free Box Shadow Generator and copy the CSS. It runs in your browser and shows a live preview.

Shadows are one of the small details that make a web page feel finished. A card that floats a little above the page reads as something you can tap. A button with a soft glow says "press me". Get the shadow wrong, though, and the same card looks dirty or dated: too dark, too sharp, or sitting off to one side like a 2005 clip-art box.

The good news is that box-shadow only has a handful of parts, and once you know what each one does, you can build almost any shadow you see on modern sites.

The box-shadow syntax, value by value

A single shadow looks like this:

box-shadow: [inset] x-offset y-offset [blur] [spread] color;

Only the two offsets are required. If you give three lengths, the third is the blur; four lengths means blur and spread.

Five shadows you can copy

These match the presets in our generator, so you can open it, click one and tweak from there.

Why layered shadows look more real

You can stack several shadows on one element by separating them with commas. The first one in the list is drawn on top. Real objects cast two kinds of shadow at once: a tight, darker one right under the edge where they touch the surface, and a wide, faint one from light scattering around them. Copying that with two layers, one small and sharp, one big and soft, is why the "Soft" example above looks more natural than any single shadow. Our generator lets you add up to five layers and edit each one separately.

Common mistakes

box-shadow or filter: drop-shadow?

box-shadow always follows the element's box, including its rounded corners from border-radius. If you want a shadow that follows the actual shape of a transparent PNG or an SVG icon, use filter: drop-shadow(0 4px 8px rgba(0,0,0,.2)) instead. Drop-shadow has no spread value and no inset option, but it traces the visible pixels rather than the rectangle.

Finish the look

A shadow works best with a matching background and readable text. Pair it with a background from our CSS gradient generator, pick colours that belong together with the colour palette generator, and check that text on your cards passes accessibility rules with the contrast checker. Then shrink the final stylesheet with the CSS minifier.

VSH take: Most design trends come and go, but soft, barely-there shadows have stuck around for years because they help people see what is clickable without shouting. If you only remember one tip, make it this: lower the opacity until you can only just see the shadow, then stop. Taking a break from code? Our free games, study tools and exam guides are a click away, and the flights hub can help if a conference trip is coming up.

ViralScopeHub is independent and not affiliated with the W3C, Mozilla or any browser maker mentioned here.

Frequently asked questions

What are the values in CSS box-shadow?

In order: an optional inset keyword, a horizontal offset, a vertical offset, an optional blur radius, an optional spread radius and a colour. Only the two offsets are required.

How do I make a soft, realistic shadow?

Use a zero horizontal offset, a small downward offset, a large blur and a low opacity, and layer two shadows: a small sharp one and a wide faint one, for example 0 4px 14px and 0 1px 3px.

Can I use more than one box-shadow?

Yes. Separate shadows with commas. The first shadow in the list is drawn on top of the others.

What does a negative spread do?

It shrinks the shadow before it is blurred, so the shadow stays tucked under the box. Combined with a big vertical offset and blur, it gives a clean lifted look.

What is the difference between box-shadow and drop-shadow?

box-shadow follows the element's rectangle and rounded corners. filter: drop-shadow follows the visible shape of the content, such as a transparent PNG, but has no spread or inset.

Is the box shadow generator free?

Yes. It is free, needs no sign-up and runs in your browser, so nothing is uploaded.

Sources

More games

All games