When box-shadow appears to do nothing, check the declaration order and color first, then look for a parent with overflow: hidden clipping the shadow or a transparent element hiding its edge. Use inset for an inner shadow, keep multiple shadows comma-separated, and remember that modern browsers support the property without vendor prefixes.
Why Your CSS Box-Shadow Isn't Working (And How to Fix It)
Box-shadow not showing up? Check overflow, missing dimensions, wrong argument order, and the drop-shadow alternative for transparent PNG logos and icons.
// The short answer
In this guide · 3 sections
You can spend hours adjusting a CSS box-shadow declaration, only to find that the element still looks completely flat. Is the syntax wrong? Is a parent clipping the shadow? Is the image’s transparency affecting its shape? Here’s how to track down those issues and stack multiple shadows cleanly.
- Basic Syntax:
box-shadow: offset-x offset-y blur-radius spread-radius color; - Inner Shadow: Add the
insetkeyword anywhere in the declaration. - Default Color: If you don’t specify a color, the shadow uses the element’s current text color.
- Browser Support: Supported by all modern browsers without vendor prefixes.
Why Your CSS Box-Shadow Isn’t Working: The Top 4 Mistakes
Most shadow problems come from layout constraints or syntax errors that the browser silently ignores.
Shadows Cut Off by Overflow: Hidden
If a card’s soft shadow looks sharply cut off, check its parent container. A parent with overflow: hidden clips anything painted outside its bounds, including the card’s shadow. Move overflow: hidden to an inner wrapper, or add enough padding to the parent to make room for the full spread and blur.
Rendering Issues on Elements Without Dimensions
A shadow needs a visible shape to follow. An empty, absolutely positioned <div> or an inline element such as <span> may have no useful footprint if it lacks dimensions or content. Make sure the target has a defined width and height, or enough block-level content to give it space on the page.
Invalid Argument Order and Silent Failures
The numeric values in box-shadow must follow a specific order: x-offset, y-offset, blur, then spread. Mixing up the values or putting a comma where a space belongs can invalidate the whole declaration. The browser drops it without showing an error in the console.
When a box-shadow disappears, check overflow, dimensions, and argument order first.
In DevTools, select the element and look at the Computed panel. If box-shadow appears there but you still can’t see a shadow, check for clipping or missing dimensions.
| Symptom | Likely cause | Fix |
|---|---|---|
| Shadow edges look cut off | Parent has overflow: hidden |
Move overflow: hidden to an inner wrapper |
| No shadow at all | Element has no width or height | Give it explicit dimensions or block content |
| Declaration is silently ignored | Wrong argument order | Use offset-x offset-y blur spread color |
| Square glow around a transparent PNG | Used box-shadow instead of filter |
Use filter: drop-shadow(...) |
Box-Shadow vs. Drop-Shadow on Transparent PNGs
A box-shadow on a transparent PNG logo creates a shadow around the image’s rectangular box, not around the logo itself. That’s because box-shadow follows the CSS box model and doesn’t account for the pixels inside it.
For a shadow that follows the image’s visible edges, use the CSS filter property: filter: drop-shadow(0px 4px 6px rgba(0,0,0,0.5));. It uses the non-transparent pixels to determine the shadow’s shape.
Box-Shadow Syntax and the Logic Behind Parameters
To build a shadow from scratch, start with the offsets. The x-offset moves it horizontally; a positive value moves it right. The y-offset moves it vertically; a positive value moves it down.
The Difference Between Blur and Spread Radius
Blur and spread do different jobs. The blur-radius softens the shadow’s edge and cannot be negative.
The spread-radius changes the shadow’s size before blur is applied. A positive value makes it larger than the element, while a negative value shrinks it. Negative spread is useful when you want a shadow beneath a card without much showing at the sides:
box-shadow: 0 4px 6px -2px rgba(0, 0, 0, 0.3);Using Inset and Multiple Shadows
Shadows can sit inside an element, too. Add inset to paint the shadow inside its border, above the background but below the content. This works well for pressed buttons and sunken form fields.
Paint Order in Comma-Separated Shadows
You can add multiple shadows by separating them with commas. Their order matters: the first shadow is painted on top, closest to the element, and the last sits at the back of the stack.
For a natural-looking effect, put a tight, dark shadow first, then add a wider, softer, lighter one behind it. This layering can suggest ambient light. Layering also helps create depth in high-performance CSS animations that stay smooth at 60 FPS.
Modern CSS Integration: Nesting and Cascade Layers
As a codebase grows, global shadow utility classes can become hard to manage. Native CSS nesting lets you keep shadow effects, hover states, and focus rings inside their component blocks without repeating class names.
Cascade layers (@layer) let you place base shadows in a utilities or design tokens layer, much as you would organize light and dark theme variables. A component state in a higher-priority layer can then override a base shadow without !important or overly specific selectors.
If a shadow works locally but disappears in production, check whether a CSS minifier or autoprefixer removed a duplicate declaration. That’s more likely than a browser bug.
Quick answers
Frequently asked questions
Why isn’t my box-shadow showing up?
The most common causes are a parent with overflow: hidden clipping the shadow, a target element with no width or height, or values in the wrong order. Check those before assuming it’s a browser bug.
How do I add a shadow to just one side of a box in CSS?
Use a small offset and a negative spread-radius. For example, box-shadow: 0 4px 6px -2px rgba(0,0,0,0.3); keeps the shadow mostly along the bottom edge instead of letting it spread out at the sides.
What’s the difference between box-shadow and filter: drop-shadow()?
box-shadow follows the rectangular CSS box, so it ignores transparency. filter: drop-shadow() follows the visible pixels, making it a better choice for transparent PNGs, SVGs, and icons.
How do I create a glowing neon box-shadow effect?
Stack two or three comma-separated shadows in the same color, increasing the blur-radius each time and leaving out spread. Put the tightest shadow first; the first value is painted closest to the element.
How do I add multiple box-shadows to one element?
Separate the shadows with commas. The first sits on top, closest to the element, while the last sits furthest back. Put the sharpest, darkest shadow first.
Does box-shadow affect page performance?
A single shadow is inexpensive to render. Performance problems are more likely when you animate box-shadow, which triggers a repaint on every frame. To animate a shadow, animate the opacity of a pseudo-element instead.
Something wrong or out of date?
Tools change fast. Tell the editor what no longer works.