Support0

CSS box-shadow playground

Combine up to three box shadows with offset, blur, spread, color, and inset, then generate copy-ready code.

Ask AI

CSS box-shadow playground

Response generated with openai/gpt-5.4-nano. AI can make mistakes. Always review the result.
Layered surface
HTML
<div class="box-shadow-sample">Layered surface</div>
Tailwind CSS
Examples for Tailwind CSS 4.3 with the default theme. Custom values keep arbitrary classes when there is no equivalent utility. Changing the theme can change utility values.
<div class="box-border grid min-block-56 w-full max-inline-88 place-items-center p-8 rounded-[24px] bg-[#f8fafc] text-[#172033] text-xl font-extrabold text-center shadow-[0px_4px_12px_-6px_#0f172a2e,0px_18px_42px_-16px_#0f172a59]">Layered surface</div>
CSS
.box-shadow-sample {
  box-sizing: border-box;
  inline-size: min(100%, 22rem);
  min-block-size: 14rem;
  display: grid;
  place-items: center;
  padding: 2rem;
  border-radius: 24px;
  background-color: #f8fafc;
  color: #172033;
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
  box-shadow:
    0px 4px 12px -6px #0f172a2e,
    0px 18px 42px -16px #0f172a59;
}

Educational guide to box-shadow

From box to shadow

Read a shadow’s values, combine several layers, and decide whether the effect should follow the box or an image’s silhouette.

Mental model

box-shadow paints one or more shadows around or inside a box. Each shadow needs two offsets. Blur, spread, color, and the inset keyword are optional.

  1. X and Y offsets

    The first two lengths move the shadow along the physical axes. Positive values move it right and down. Negative values move it left and up.

  2. Blur

    The third length softens the edge. Zero gives a sharp edge. Negative values are invalid.

  3. Spread

    The fourth length grows the shaded area if positive and shrinks it if negative. Write the blur value, even when zero, before specifying spread.

Static diagram of one layerRead the lengths in order, then look for a color and the inset keyword. Omitted blur and spread are zero, and an omitted color uses currentColor.

Outer and inner geometry

An outer shadow starts from the border box and follows its rounded corners. With inset, the padding box is the reference and the shadow is painted inside that inner edge.

The same lengths, outside and inside

Outer Neighbor
Inner Neighbor
With the same positive values, the outer shadow shows below and to the right, and the inner shadow collects along the top and left. Both neighboring boxes start in the same column.
The same lengths, outside and inside
<div class="box-shadow-guide-geometry">
  <div>
    <span class="tile outer">Outer</span>
    <span class="tile">Neighbor</span>
  </div>
  <div>
    <span class="tile inner">Inner</span>
    <span class="tile">Neighbor</span>
  </div>
</div>
.box-shadow-guide-geometry {
  display: grid;
  gap: 1rem;
  padding: 0.75rem;

  > div {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .tile {
    padding: 0.75rem;
    border: 1px solid #475569;
    border-radius: 0.5rem;
    overflow-wrap: anywhere;
    background-color: #f8fafc;
    color: #172033;
  }

  .outer {
    box-shadow: 6px 8px 0 2px #2563eb;
  }

  .inner {
    box-shadow: inset 6px 8px 0 2px #2563eb;
  }
}

The shadow leaves the box dimensions and spacing intact. To make room for it, use gap, padding, or margin where appropriate. An ancestor that clips overflow can hide part of the outer shadow.

Layers and painting order

Separate shadows with commas in one declaration. Among outer shadows, the first is in front, with the rest layered behind it. Inner shadows are drawn above the background and outer shadows beneath it.

Two shadows in reverse order

Blue first

Amber first

The same blue and amber shadows swap places in the list. Where they overlap along the bottom, the first color in the list is visible.
Two shadows in reverse order
<div class="box-shadow-guide-layers">
  <p class="blue-first">Blue first</p>
  <p class="amber-first">Amber first</p>
</div>
.box-shadow-guide-layers {
  display: grid;
  gap: 1rem;
  padding: 0.75rem;

  p {
    margin: 0;
    padding: 0.75rem;
    border-radius: 10px;
    background-color: #fde68a;
    color: #172033;
  }
}

.box-shadow-guide-layers .blue-first {
  box-shadow:
    10px 10px 0px 0px #2563eb,
    14px 6px 0px 0px #d97706;
}

.box-shadow-guide-layers .amber-first {
  box-shadow:
    14px 6px 0px 0px #d97706,
    10px 10px 0px 0px #2563eb;
}

To give a card depth, try a close shadow with a little blur as the first layer and a broader, softer shadow as the second. Adjust both on the actual surface.

Box versus silhouette

Use box-shadow to follow the geometry of a box. Use filter: drop-shadow() to cast the silhouette of the painted pixels, such as an image with transparency.

Two triangles on transparent backgrounds

box-shadow

drop-shadow()

Both use the same offset and zero blur. On the left, a rectangular shadow sits behind the SVG box. On the right, the shadow follows the triangle’s sides.
Two triangles on transparent backgrounds
<div class="box-shadow-guide-silhouette">
  <div>
    <p>box-shadow</p>
    <svg viewBox="0 0 64 64" aria-hidden="true" focusable="false"><path fill="currentColor" d="M32 4 60 58H4Z"/></svg>
  </div>
  <div>
    <p>drop-shadow()</p>
    <svg viewBox="0 0 64 64" aria-hidden="true" focusable="false"><path fill="currentColor" d="M32 4 60 58H4Z"/></svg>
  </div>
</div>
.box-shadow-guide-silhouette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  padding: 0.5rem;
  overflow-wrap: anywhere;

  p {
    margin-block: 0 0.5rem;
  }

  svg {
    display: block;
    inline-size: min(100%, 4rem);
    block-size: auto;
    color: #2563eb;
  }

  > :first-child svg {
    box-shadow: 8px 8px 0 #64748b;
  }

  > :last-child svg {
    filter: drop-shadow(8px 8px 0 #64748b);
  }
}

The third length in drop-shadow() is the standard deviation of the Gaussian blur. The function accepts up to three lengths. For an inner shadow or spread control, use box-shadow.

Visible focus with or without a shadow

Use the shadow for depth and keep the browser’s focus indicator. When customizing focus, apply a contrasting outline with :focus-visible.

A disclosure with a focus outline

View details

The native disclosure keeps its outline while the summary has focus.

Tab to the summary and open it with Enter or Space. The outline marks focus. In forced colors, the shadow disappears and the outline uses the Highlight system color.
A disclosure with a focus outline
<details class="box-shadow-guide-focus">
  <summary>View details</summary>
  <p>The native disclosure keeps its outline while the summary has focus.</p>
</details>
.box-shadow-guide-focus {
  padding: 0.375rem;

  summary {
    padding: 0.5rem;
    border: 1px solid currentColor;
    box-shadow: 0 3px 6px -2px #64748b;

    &:focus-visible {
      outline: 2px solid currentColor;
      outline-offset: 3px;

      @media (forced-colors: active) {
        outline-color: Highlight;
      }
    }
  }

  p {
    margin-block: 0.75rem 0;
  }
}

Common pitfalls

The second declaration replaces the first

Expected result
Both shadows appear together.
Cause
Two box-shadow declarations on the same box compete in the cascade.
Solution
Combine the layers with commas and put the frontmost layer first.

The shadow overlaps a neighboring box

Expected result
There is enough room to see the entire shadow.
Cause
The shadow adds paint while the layout keeps the same space between boxes.
Solution
Increase the layout spacing or reduce the extent of the shadow.

Support and compatibility

box-shadow and the drop-shadow() filter function are widely available. Their appearance depends on the geometry and what is painted behind them.

In forced colors, the browser removes box-shadow. When a control’s boundary or state matters, also use a border or outline that stays visible.