DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
box-shadow

How to Add Shadows to PNG Images in HTML and CSS

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use filter: drop-shadow() when a transparent PNG’s shadow should follow the visible artwork. Use box-shadow when you want a shadow around the image element’s rectangular box. These properties produce different geometry, so choosing the right one matters more than changing blur or color.

Use drop-shadow() for a transparent PNG silhouette

A PNG can contain transparent pixels around a logo, icon, product cutout, or irregular illustration. The CSS drop-shadow() filter reads the rendered image’s alpha mask and places a blurred, offset copy beneath the visible pixels.

<img class="logo" src="logo.png" alt="Company logo">
.logo {
  filter: drop-shadow(4px 6px 8px rgb(0 0 0 / 0.35));
}

The first length moves the shadow horizontally; the second moves it vertically. Positive values move right and down, while negative values move left and up. The optional third length controls blur. The color can appear before or after the lengths. If you omit the color, the filter uses the element’s color value. See MDN’s drop-shadow() reference.

A sharp or unblurred shadow

Omit the blur length, or set it to zero, when you want a crisp offset edge.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
.icon {
  filter: drop-shadow(3px 3px 0 rgb(0 0 0 / 0.45));
}

This is useful for pixel-art effects, stickers, and small icons where a large blur can make the result muddy.

A soft shadow with explicit opacity

.product-cutout {
  filter: drop-shadow(0 12px 18px rgb(0 0 0 / 0.22));
}

An explicit color and alpha value makes the result predictable against different backgrounds. A semi-transparent black is a common starting point, but a tinted shadow can better match a colored interface.

Use box-shadow for the image element’s rectangle

box-shadow shadows the element’s box, not the non-transparent portions of the file. It is therefore appropriate for a rectangular photograph, a framed preview, or a card containing an image.

.preview {
  box-shadow: 0 8px 20px rgb(0 0 0 / 0.2);
}

Applied directly to an irregular transparent PNG, this creates a rectangular shadow that includes empty transparent space. If that is not the intended appearance, switch to filter: drop-shadow().

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

drop-shadow() versus box-shadow

Feature filter: drop-shadow() box-shadow
Shadow shape Follows the rendered PNG alpha mask Follows the element’s rectangular box
Required geometry Horizontal and vertical offsets Horizontal and vertical offsets
Blur Optional third length Optional blur radius
Spread Not supported Optional spread radius
Inset effect Not supported Supports the inset keyword
Multiple shadows Repeat drop-shadow() functions in one filter list Separate shadows with commas

MDN documents the available box-shadow values, while the W3C describes one or more shadows attached to a box in the CSS Backgrounds and Borders Module Level 3.

Build layered shadows

For a stronger edge plus a softer falloff, repeat the filter function in a space-separated list.

.logo {
  filter: drop-shadow(2px 3px 3px rgb(0 0 0 / 0.35))
          drop-shadow(0 0 1px rgb(0 0 0 / 0.2));
}

Functions run in the order written. Inspect the complete list when another filter, such as brightness() or grayscale(), changes the appearance. Filter effects are covered in MDN’s Using filter effects guide.

Control the effect with custom properties

Custom properties make one shadow recipe reusable across themes and component sizes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
:root {
  --png-shadow-x: 0px;
  --png-shadow-y: 8px;
  --png-shadow-blur: 16px;
  --png-shadow-color: rgb(0 0 0 / 0.24);
}

.hero-art {
  filter: drop-shadow(
    var(--png-shadow-x)
    var(--png-shadow-y)
    var(--png-shadow-blur)
    var(--png-shadow-color)
  );
}

[data-theme="dark"] {
  --png-shadow-color: rgb(0 0 0 / 0.55);
}

Keep the alpha channel modest on busy backgrounds. A very dark shadow can reduce nearby text contrast even when the image itself is decorative.

Complete responsive example

This example uses drop-shadow() for a transparent product cutout and changes only the offset and blur at a wider viewport.

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
<figure class="product-figure">
  <img
    class="product-figure__image"
    src="headphones.png"
    alt="Black wireless headphones"
    width="800"
    height="600"
  >
  <figcaption>Wireless headphones</figcaption>
</figure>
.product-figure {
  max-width: 32rem;
  margin: 2rem auto;
  text-align: center;
}

.product-figure__image {
  display: block;
  width: min(100%, 800px);
  height: auto;
  filter: drop-shadow(0 8px 12px rgb(0 0 0 / 0.24));
}

@media (min-width: 48rem) {
  .product-figure__image {
    filter: drop-shadow(0 16px 24px rgb(0 0 0 / 0.22));
  }
}

Declaring intrinsic width and height helps the browser reserve layout space while the PNG loads. display: block removes the default inline-image baseline gap; it does not affect the shadow geometry.

What drop-shadow() cannot do

  • There is no spread value in the function. To imitate a thicker outline, stack another low-blur shadow or edit the source artwork.
  • There is no inset keyword. An inner shadow requires a different technique, such as a clipped pseudo-element or an SVG effect.
  • The shadow follows the pixels the browser renders. Transparent padding in the file does not become an opaque rectangle, but semi-transparent pixels can produce correspondingly soft edges.

Fix clipping, overrides, and unexpected geometry

The shadow is rectangular

Check the computed style and replace box-shadow with filter: drop-shadow(...) when the visible silhouette is the desired outline.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The shadow is too hard or too soft

Change the third length in drop-shadow(). Lower values sharpen the edge; higher values spread the blur. Adjust opacity separately so you do not use blur to compensate for an overly dark color.

The shadow is on the wrong side

Verify the signs of both offsets. For example, drop-shadow(-6px -4px 8px ...) moves the effect left and upward.

The shadow is invisible

  • Set an explicit color such as rgb(0 0 0 / 0.3).
  • Inspect the browser’s computed styles for a later rule that resets filter to none.
  • Check whether another filter list replaces the entire declaration. CSS does not merge separate filter declarations; the winning declaration supplies the complete list.

The shadow is clipped

Blurred and offset pixels can extend outside the image’s box. An ancestor with overflow: hidden or another constrained clipping region may cut them off. Remove or relax that constraint where possible, or provide surrounding layout space. The required space depends on the offsets and blur, so verify it at the largest rendered size rather than choosing a universal margin.

Accessibility, rendering, and browser support

Shadow is decoration and should not replace meaningful contrast, labels, or focus indicators. Keep useful alternative text on informative images and use an empty alt attribute for purely decorative PNGs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Filters are widely available. MDN marks drop-shadow() as broadly supported since September 2016. If your product supports unusually old browsers or a fixed device fleet, check the current MDN compatibility table and test the actual targets. Test large, full-page images as well as small icons: blur and multiple filters can increase rendering work, especially when many filtered elements are visible at once.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup:

If your goal is to obtain a clean rendered image after applying your CSS, ScreenshotNeo can capture the page through one HTTP request. It accepts cookie and consent banners like a visitor, then removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response reports the result through X-Page-Verdict and X-Billed headers.

The API supports PNG, JPEG, WebP, and PDF output, full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets, arbitrary viewports, retina scale, custom CSS and JavaScript, clicks, waits, blocked requests, custom headers and cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, selectable cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Its parameter names are compatible with those used by other screenshot APIs, which can simplify migration.

Use the ScreenshotNeo documentation for the complete option list. Here are runnable requests for a page containing the PNG shadow:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo includes an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.

Quick decision checklist

  • Choose drop-shadow() when the shadow must follow transparent artwork.
  • Choose box-shadow when the rectangular image or card frame should cast the shadow.
  • Use two offsets, then tune blur and opacity.
  • Stack filter functions for layered effects, remembering that order matters.
  • Inspect clipping ancestors and competing filter declarations when the result is missing or cut off.

Frequently Asked Questions

Can I use both box-shadow and drop-shadow() on one PNG?

Yes. They are independent effects, so you can combine them when you intentionally want both a silhouette shadow and a rectangular frame shadow. Check the result at the image’s real size to avoid an overly heavy edge.

Which value moves a shadow upward?

Use a negative vertical offset, such as drop-shadow(0 -6px 10px rgb(0 0 0 / 0.3)). The second length is the vertical offset.

Does a PNG need to be edited before using CSS shadows?

No. A transparent PNG can be shadowed directly in CSS. The browser derives the silhouette from the rendered alpha channel.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why does my filter disappear when I add another filter?

A later filter declaration replaces the earlier declaration rather than appending to it. Put all required functions in one winning filter list.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.