Lesson 38 +10 XP

Box Shadow

Box Shadow

Shadows add depth to elements. Tailwind uses CSS variables that compose, so multiple shadow utilities can be combined.

Basic shadows

ClassCSS
shadow-sm0 1px 3px 0 rgb(0 0 0 / 0.1)
shadow0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px
shadow-md0 4px 6px -1px, 0 2px 4px -2px
shadow-lg0 10px 15px -3px, 0 4px 6px -4px
shadow-xl0 20px 25px -5px, 0 8px 10px -6px
shadow-2xl0 25px 50px -12px
shadow-nonenone
<div class="shadow-md">...</div>

Shadow color

Tint the shadow with shadow-<color>:

<div class="shadow-md shadow-sky-500/20">...</div>

Inset shadows

inset-shadow-sm, inset-shadow, inset-shadow-md, inset-shadow-lg, inset-shadow-xl, inset-shadow-2xl. Inner shadows are separate from outer shadows.

Custom shadows with @theme

@theme {
  --shadow-beans: 0 4px 14px -2px rgb(84 15 42 / 0.7);
}

Generates shadow-beans.

Combining shadow layers

Shadow utilities compose via variables:

<div class="shadow-md shadow-sky-500/20 inset-shadow-sm">...</div>

TL;DR

  • shadow-smshadow-2xl add depth.
  • shadow-<color> tints the shadow.
  • inset-shadow-* add inner shadows.
  • Define custom shadows with --shadow-* in @theme.