Syntax of the CSS box-shadow property
The box-shadow property adds one or more drop shadows to the frame of an HTML element. It follows a very specific order:
- X offset (offset-x): The horizontal axis. A positive value pushes the shadow to the right, a negative value to the left.
- Y offset (offset-y): The vertical axis. A positive value pushes the shadow down, a negative value up.
- Blur radius (blur-radius): The higher the value, the more diffuse, wide and light the shadow. At 0, the shadow is sharp (solid).
- Spread (spread-radius): A positive value enlarges the shadow on all sides, a negative value shrinks it.
- Color: Usually defined in RGBA to handle the shadow's transparency over its background.
- Inset : Optional keyword to place the shadow inside the element (inset effect).
UI design tip: how do you make a nice shadow?
The classic beginner mistake is to use a fully opaque black shadow or one with very little blur, which makes the design look "dirty" or dated. For a modern interface (Material Design or Apple-like):
Always use the RGBA format (black color 0,0,0) with a very low opacity (between 0.05 and 0.15), and compensate with a large blur radius (e.g. 20px to 40px). The shadow will look natural and diffuse, as if cast by a real ambient light source.