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
| Field | Default | Effect |
|---|---|---|
| Horizontal offset (px) | 0 | Moves the shadow right (positive) or left (negative). |
| Vertical offset (px) | 8 | Moves the shadow down (positive) or up (negative). |
| Blur (px) | 24 | How soft the edge is. Zero gives a hard edge. |
| Spread (px) | 0 | Grows the shadow (positive) or shrinks it (negative) before blurring. |
| Shadow colour (hex) | #000000 | The base colour, as a 3 or 6 digit hex code. |
| Opacity (%) | 20 | How see-through the colour is, from 0 to 100. |
| Type | Outer shadow | Or Inner (inset) shadow, drawn inside the box. |
| Layers | One layer | Or 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?
How do I make a soft shadow in CSS?
What does a negative spread do in box-shadow?
How do I add a shadow only at the bottom of a box?
What is the difference between box-shadow and drop-shadow?
Does box-shadow affect layout or spacing?
Related guides
- Free Developer Tools That Replace a Dozen Browser Tabs Free developer tools grouped by job: format, convert, encode, generate and test. What each one does, which run on the server, and the limits to know f...
- How to Beautify CSS, HTML and XML (Online, VS Code, Prettier) Beautifying adds line breaks and indentation so minified CSS, HTML or XML is readable again. How the free formatters work, their limits, and VS Code a...
- How to Format JSON: Pretty-Print, Validate and Read Errors Paste JSON into a formatter to indent it and catch errors. The exact syntax rules, how to read an error position, and how to do it in VS Code, Python...