What Is a CSS Box Shadow?
The CSS box-shadow property attaches one or more shadow effects to an HTML element's bounding box. Each shadow layer is described by a set of length values — horizontal offset, vertical offset, blur radius, and spread radius — combined with a color value. You can also prepend the keyword inset to push the shadow inside the element's padding edge rather than outside its border edge. The complete syntax for a single shadow is: box-shadow: [inset] offsetX offsetY blurRadius spreadRadius color; and multiple layers are comma-separated, rendered front to back.
Box shadows are one of the most versatile visual tools in CSS. Designers use them to give cards a sense of elevation, to draw attention to modal dialogs, to simulate depth in flat design systems, and to create inner-glow or inset-pressed effects for form inputs and buttons. Because shadows respect the element's border-radius, a pill-shaped button receives a correctly shaped shadow without any extra work. Unlike filter: drop-shadow(), box-shadow does not bleed through transparent areas of an image — it follows the element's layout box, making it predictable and easy to reason about in complex layouts.
Understanding the relationship between blur and spread helps you achieve precise results. Blur diffuses the shadow outward: a blur of 0 gives a hard, opaque edge identical to the element's outline, while higher values create soft, painterly halos. Spread shifts the shadow's size before blur is applied: a positive spread value makes a shadow that extends further than the element, useful for creating visible outlines without affecting layout flow, since box shadows do not occupy space in the document flow. A negative spread on an offset shadow creates the popular "directional shadow under a lifting card" effect.
Stacking multiple shadow layers on a single element produces effects that a single layer cannot achieve. A common pattern used in modern design systems combines a tight, dark base shadow with a larger, lighter ambient shadow to simulate realistic light diffusion. Another popular multi-layer approach stacks an inner border shadow (using negative spread with zero offset) on top of a regular elevation shadow to give elements a subtle bordered-card treatment without adding extra DOM elements. This generator builds comma-separated multi-layer output ready to paste directly into any stylesheet or design token file.