Resell services with the EthicalSMM API

CSS Box Shadow Generator

Build a CSS box-shadow from offset, blur, spread, colour and opacity, preview it on a card and copy the code, including soft layered shadows.

Was this tool helpful?

Thanks for the feedback!

This generator builds a CSS box-shadow from offset, blur, spread, colour and opacity, shows it on a white card and gives you the code to copy. It can also stack two layers for a softer, more natural shadow. It suits web designers, developers and anyone tweaking a theme who wants to see a shadow before committing it to a stylesheet.

The fields and what they control

FieldDefaultEffect
Horizontal offset (px)0Moves the shadow right (positive) or left (negative).
Vertical offset (px)8Moves the shadow down (positive) or up (negative).
Blur (px)24How soft the edge is. Zero gives a hard edge.
Spread (px)0Grows the shadow (positive) or shrinks it (negative) before blurring.
Shadow colour (hex)#000000The base colour, as a 3 or 6 digit hex code.
Opacity (%)20How see-through the colour is, from 0 to 100.
TypeOuter shadowOr Inner (inset) shadow, drawn inside the box.
LayersOne layerOr Two layers (softer, more natural).

How the shadow code is built

The tool turns your hex colour and opacity into an rgba() colour. A three-digit code such as #000 is expanded to #000000, the leading # is optional, and opacity is divided by 100 and rounded to two decimals. The values are then written in the order CSS expects: the word inset if you chose an inner shadow, then horizontal offset, vertical offset, blur, spread and colour.

With Two layers, the tool adds a second, tighter shadow in front of yours. Its offsets and blur are one third of yours, rounded to whole pixels, the spread stays the same and the opacity is halved. A small close shadow plus a wide faint one looks closer to how light falls on a real object than one big blur does.

Worked examples

The defaults with one layer give the classic card shadow:

box-shadow: 0px 8px 24px 0px rgba(0, 0, 0, 0.2);

Switch to two layers and the tool adds a 3px, 8px blur layer at half strength (8 ÷ 3 rounds to 3, 24 ÷ 3 is 8, and 20% halves to 0.1):

box-shadow:
  0px 3px 8px 0px rgba(0, 0, 0, 0.1),
  0px 8px 24px 0px rgba(0, 0, 0, 0.2);

A tinted shadow often looks better on a coloured button than grey. With colour #7c3aed, opacity 25, vertical offset 12, blur 30, spread −4 and two layers, the output is:

box-shadow:
  0px 4px 10px -4px rgba(124, 58, 237, 0.13),
  0px 12px 30px -4px rgba(124, 58, 237, 0.25);

The negative spread pulls the shadow in at the sides so it shows mostly below the button. For a pressed input or a well, an inner shadow such as inset 0px 2px 6px 0px rgba(0, 0, 0, 0.15) works well.

Common mistakes and the tool's checks

  • Colour names and rgb() values are not accepted in the colour box. Typing "black" gives "Enter the colour as a hex code like #000000." Convert other formats first with the colour converter.
  • A negative blur is invalid in CSS, and the tool says "Blur cannot be negative." Negative offsets and negative spread are fine.
  • Opacity above 100 or below 0 gives "Opacity must be between 0 and 100."
  • Heavy shadows look muddy. On a light background, opacity between 10 and 25 percent with a generous blur usually reads as depth rather than a dark smudge.
  • A shadow should not be the only sign that a button has keyboard focus. Pair it with an outline or a colour change that has enough contrast, which you can test with the colour contrast checker.

The shadow follows the element's border-radius, so a rounded card gets a rounded shadow. It does not take up space in the layout, but a parent with overflow: hidden can clip it.

On a dark background, a black shadow at 20% barely shows. In a dark theme, depth usually comes from making raised surfaces a slightly lighter shade, sometimes with a thin border, so check the shadow in both themes before you settle on it. If you need a matching background, the CSS gradient generator writes that code in the same way.

Frequently asked questions

What do the four numbers in box-shadow mean?
In order they are horizontal offset, vertical offset, blur radius and spread radius, followed by the colour. Only the two offsets are required; blur and spread default to zero.
How do I make a soft shadow in CSS?
Use a low opacity, a large blur and a modest vertical offset, and stack two layers. With the defaults and two layers, the tool gives 0px 3px 8px 0px rgba(0, 0, 0, 0.1) followed by 0px 8px 24px 0px rgba(0, 0, 0, 0.2).
What does a negative spread do in box-shadow?
It shrinks the shadow before the blur is applied, so less of it shows around the sides. Combined with a vertical offset, it makes a shadow that sits mostly under the element.
How do I add a shadow only at the bottom of a box?
Use a vertical offset with a negative spread close to the blur. For example, vertical offset 10, blur 10, spread -8 and opacity 30 gives box-shadow: 0px 10px 10px -8px rgba(0, 0, 0, 0.3);
What is the difference between box-shadow and drop-shadow?
box-shadow follows the rectangle of the element and its rounded corners. The CSS filter drop-shadow() follows the visible shape, such as a transparent PNG, and this tool writes box-shadow only.
Does box-shadow affect layout or spacing?
No. A shadow does not take up space or push other elements, but it can be cut off if a parent element has overflow set to hidden.

Related guides

Related tools

People also used

Embed this tool on your site

Paste it into any blog or website. Free, with a credit link.