Shadows¶
Shadows suggest depth. CSS has box-shadow for boxes and text-shadow for text. Use them sparingly; a page with a shadow on everything becomes harder to read.
Box shadow¶
The syntax is:
You rarely need spread. A small vertical offset and a soft blur usually look more natural than a large, dark shadow.
You can layer two shadows for a more natural result:
Inset shadows¶
inset draws the shadow inside the box.
Text shadow¶
Use text shadow mainly to lift text off a busy image. It is not a substitute for good contrast.
Keep shadows consistent¶
:root {
--shadow-sm: 0 1px 2px rgb(0 0 0 / 0.08);
--shadow-md: 0 4px 12px rgb(0 0 0 / 0.12);
}
.card {
box-shadow: var(--shadow-sm);
}
A small set of shadow values keeps the interface consistent.
Try it¶
- Add a small shadow to a card.
- Increase the blur and offset, then reduce them again. Which version is easier to read?
- Layer two shadows and compare them with a single shadow.
- Add a text shadow to a title on a dark background.
- Remove the shadow from body text. Text shadows usually make long text harder to read.
If the shadow looks like a dark border, reduce the opacity and increase the blur.
Next: Typography