Inner Shadow in CSS: 10 inset box-shadow Recipes
Ten tested inset box-shadow recipes (input well, pressed button, one-sided, inner border, vignette), plus why inset shadows vanish behind images and child backgrounds.
On this page ⌄
An inner shadow in CSS is box-shadow with the inset keyword: box-shadow: inset 0 2px 4px rgba(0,0,0,.2). The shadow is drawn inside the element's padding box, on top of its background. The syntax is easy; the parts that trip people up are covering only one side, putting an inner shadow on an image, and what is drawn above what. Each of those was checked by sampling screenshot pixels in Chrome 156, and the recipes below are the ones that rendered correctly. To design your own with a live preview, use the Box Shadow Generator.
How the offsets work
box-shadow: inset offset-x offset-y blur spread color;
With inset, the shadow is cast from the outside edges inward, so a positive offset-y puts the shadow along the top edge and a positive offset-x along the left edge. That is the opposite of an outer shadow, where positive values push it down and right. Confirmed: inset 0 4px 4px -4px #000 produced a grey band at the top of the box and nothing at the bottom.
Ten recipes
All use plain box-shadow; swap the colours for your palette.
| # | effect | declaration |
|---|---|---|
| 1 | input well | inset 0 2px 4px rgba(0,0,0,.08) |
| 2 | pressed button | inset 0 3px 6px rgba(0,0,0,.35) plus transform: translateY(1px) |
| 3 | neumorphic pressed | inset 6px 6px 12px #a3b1c6, inset -6px -6px 12px #fff |
| 4 | inner glow | inset 0 0 20px rgba(99,102,241,.5) |
| 5 | top edge only | inset 0 4px 4px -4px rgba(0,0,0,.4) |
| 6 | bottom edge only | inset 0 -4px 4px -4px rgba(0,0,0,.4) |
| 7 | inner border ring | inset 0 0 0 2px #6366f1 |
| 8 | image vignette | inset 0 0 60px rgba(0,0,0,.5) on an overlay (see below) |
| 9 | sunken, light lower lip | inset 0 2px 5px rgba(0,0,0,.2), 0 1px 0 rgba(255,255,255,.7) |
| 10 | dark theme well | inset 0 2px 6px rgba(0,0,0,.6), inset 0 0 0 1px rgba(255,255,255,.05) |
All ten were rendered on a test page and the output inspected. One note on #3: neumorphism only reads correctly when the element's background matches the page background (#e0e5ec in the classic version). On a different page colour it looks like a smudge.
Pressed button
.btn {
background: #4f46e5;
color: #fff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(79,70,229,.3);
transition: box-shadow .1s, transform .1s;
}
.btn:active {
box-shadow: inset 0 3px 6px rgba(0,0,0,.35);
transform: translateY(1px);
}
Replacing the outer shadow with an inset one in the :active state is what sells the press.
Shadow on one side only
Use a negative spread equal to the blur. The negative spread shrinks the shadow's edge so the blur only reaches the side the offset pushes it towards:
.top-only { box-shadow: inset 0 4px 4px -4px rgba(0,0,0,.4); }
.bottom-only { box-shadow: inset 0 -4px 4px -4px rgba(0,0,0,.4); }
.left-only { box-shadow: inset 4px 0 4px -4px rgba(0,0,0,.4); }
Measured on a white 100px box with the top version: the pixel at the top edge was RGB(198,198,198), back to 245 at 3px in, and the middle, bottom and left edges stayed white. The rule of thumb is that offset, blur and the negative spread should be the same size, otherwise the shadow leaks onto a second side.
Inner border without changing layout
inset 0 0 0 2px colour draws a solid ring inside the box. Unlike border it adds no width, so nothing around it shifts when you toggle it on focus:
.field { box-shadow: inset 0 0 0 1px #d1d5db; }
.field:focus { box-shadow: inset 0 0 0 2px #2563eb; outline: none; }
Where a real border also exists, the inset shadow starts inside it. Tested with a 10px red border and inset 0 0 0 10px blue, the first 10px were red, the next 10px blue, then the background. Only remove outline for focus when something equally visible replaces it, as above.
Inner shadow on an image
This is the most common failing case. Apply inset directly to an <img> and nothing shows: with box-shadow: inset 0 0 0 20px blue on a red image, the pixel 10px in was still pure red. The image's own pixels paint above its element's inset shadow, so the shadow is hidden behind them.
The fix is a wrapper with an overlay pseudo-element that sits above the image:
<figure class="shaded"><img src="photo.jpg" alt=""></figure>
.shaded { position: relative; display: inline-block; margin: 0; }
.shaded img { display: block; }
.shaded::after {
content: "";
position: absolute;
inset: 0;
box-shadow: inset 0 0 60px rgba(0,0,0,.5); /* recipe 8, vignette */
pointer-events: none; /* clicks reach the image */
}
With this structure the same 20px blue ring test rendered pure blue 10px in. The same thing happens with any child that has its own background: a green child with inset: 0 inside a box with an inset shadow fully hid the shadow. Either move the shadow to an ::after overlay, or give the child a transparent background.
Order and combining shadows
Several shadows go in one comma-separated list, and the first listed is drawn on top. Tested with a 20px blue ring and a 40px red ring:
| order | pixel 10px in | pixel 30px in |
|---|---|---|
| blue 20px, then red 40px | blue | red |
| red 40px, then blue 20px | red | red |
In the second case the red ring covers the blue one completely, which is a classic reason a shadow seems to do nothing. Put the smaller or more important shadow first.
Inset and outer shadows can share a declaration. With inset 0 0 0 10px blue, 0 0 0 10px red, the pixel 5px inside the box was blue and the pixel 5px outside was red, so the two do not interfere:
.field-well {
box-shadow:
inset 0 2px 4px rgba(0,0,0,.08), /* well */
0 1px 0 rgba(255,255,255,.7); /* light lower lip */
}
On rounded elements the inset shadow follows border-radius: with border-radius: 50% the corner pixel outside the circle stayed untouched.
FAQ
How do I add an inner shadow to an image in CSS?
Wrap the image and put the inset shadow on an ::after overlay with position: absolute; inset: 0; pointer-events: none. A direct box-shadow: inset on the <img> is painted behind the image pixels and does not show.
How do I make an inset box shadow on top only?
box-shadow: inset 0 4px 4px -4px rgba(0,0,0,.4). Keep the offset, blur and negative spread the same size. Flip the offset sign for the bottom edge.
Can I do an inner border with box-shadow?
Yes: box-shadow: inset 0 0 0 2px #6366f1. It draws inside the box and does not change the element's size, unlike border.
Why is my inset box-shadow not showing?
Three reproduced causes: it is on an <img>, a child element has an opaque background that covers it, or an earlier shadow in the list is bigger and covers it. Also check the colour has enough alpha to be visible.
Do inset shadows hurt performance?
Static ones do not. Animating any box-shadow repaints, so see the measured box-shadow performance numbers before animating one over many elements.
Tested
Run on 2026-11-02 with Chrome 156.0.8078.48 (headless, playwright-core, Windows 11). Pixel values come from screenshots read back through a canvas; the ten recipes were also rendered and inspected as a contact sheet. Firefox and Safari were not tested. To pick colours that match your theme, use the Color Picker.
Keep reading
Related tools
Box Shadow Generator
Visual CSS box-shadow builder. Control offset, blur, spread, color, inset. Multi-layer shadows. Live preview + copyable CSS.
WebP to JPG Converter
Convert WebP to JPG, PNG or WebP in your browser. Batch files, set quality, pick a background for transparency. Nothing is uploaded.
Image Compressor
Compress JPEG, PNG, and WebP images in your browser. Adjustable quality, batch mode. Files never leave your device.
Color Picker
Pick colors, convert hex/RGB/HSL/OKLCH, and check WCAG contrast.
Written by Mian Ali Khalid. More guides in Frontend & Design.