CSS Box Shadow Generator: how it works and how to build one
Build layered box shadows visually and copy the CSS. This guide explains what happens behind the button and shows the code, so you can build your own.
What it does
Set offset, blur, spread, color and opacity for one or more shadow layers, including inset shadows, and see them on a card. Presets include soft, hard (like this site) and neumorphic styles.
When to use it
- Cards and modals
- Buttons
- Neumorphic and hard-shadow styles
How to use it
- Pick a preset or add layers.
- Adjust each layer with sliders.
- Copy the box-shadow CSS.
Try it free in your browser, nothing is uploaded: https://eskillsfy.com/tools/box-shadow-generator
How it works
box-shadow takes a comma-separated list of shadows, each with an x and y offset, blur radius, spread and color, and an optional inset keyword. Layering two or three soft shadows (a tight one and a wide one) looks more natural than one big shadow.
The tool keeps an array of layer objects and joins them into the CSS string on every change.
Build it yourself
Here is the core of the tool. It has no dependencies unless noted, so you can paste it into any TypeScript or JavaScript project.
shadow.ts (ts)
type Layer = { x: number; y: number; blur: number; spread: number; color: string; alpha: number; inset?: boolean };
const rgba = (hex: string, a: number) => {
const v = parseInt(hex.slice(1), 16);
return `rgba(${v >> 16}, ${(v >> 8) & 255}, ${v & 255}, ${a})`;
};
export const boxShadow = (layers: Layer[]) =>
layers.map((l) => `${l.inset ? "inset " : ""}${l.x}px ${l.y}px ${l.blur}px ${l.spread}px ${rgba(l.color, l.alpha)}`).join(", ");
Make it production-ready
- Add hover-state preview.
- Export as Tailwind arbitrary values.
Questions
Why use several layers?
Two or three soft layers look more natural than one big blurry shadow.
Free, runs in your browser, nothing is uploaded.