Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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
World desk2 min

CSS box-shadow: A Practical Guide with Examples

Add outer, inset, and layered CSS shadows. This practical guide explains offsets, blur, spread, color, ordering, and browser support.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use box-shadow to add a shadow outside an element’s frame or, with inset, inside it. A shadow can be tuned with horizontal and vertical offsets, blur, spread, and color; you can also stack several shadows in one declaration.

How to add a basic shadow in CSS

Put a box-shadow declaration in the rule for the element you want to style:

As an Amazon Associate I earn from qualifying purchases.

.card {
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.16);
}

This example places the shadow four pixels down, gives it a 12-pixel blur, and uses a translucent black color. The values are an illustrative starting point, not a universal recipe: adjust them to suit the design. See the MDN Web Docs reference for box-shadow for the full syntax and examples.

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

What the values in box-shadow mean

The general pattern is box-shadow: [inset] <offset-x> <offset-y> [<blur-radius> [<spread-radius>]] [<color>]. Only the horizontal and vertical offsets are required; blur, spread, color, and inset are optional.

#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
Value What it controls
offset-x Horizontal displacement. A negative value moves the shadow left.
offset-y Vertical displacement. A negative value moves the shadow upward.
blur-radius How soft the edge is. It cannot be negative.
spread-radius How much the shadow expands or contracts. Positive values expand it; negative values contract it. If omitted, it is zero.
color The shadow color. If omitted, it uses the element’s color value, as documented by MDN.
inset Changes the shadow from an outer shadow to an inner one.

For a crisp outline-like shadow, set blur to zero and use spread to set its size:

.badge {
  box-shadow: 0 0 0 2px rebeccapurple;
}

For a more subtle result, a low-opacity color can keep the shadow from overpowering the element.

How to make an inset shadow

Add inset before the offset values. The shadow is rendered inside the frame, above the background and below the content, rather than falling outside the element. This example places a soft shadow toward the bottom of an input:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
.input {
  box-shadow: inset 0 2px 4px rgb(0 0 0 / 0.18);
}

The W3C CSS Backgrounds and Borders Module Level 3 specifies the behavior of shadows, including inset shadows.

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

How to add multiple shadows

Separate complete shadow values with commas. Each shadow can have its own offsets, blur, spread, color, and inset setting. The first shadow in the list is painted on top of the later ones.

.panel {
  box-shadow: 0 2px 4px rgb(0 0 0 / 0.12),
              0 10px 24px rgb(0 0 0 / 0.10);
}

Here, the smaller shadow sits above the broader, softer layer. Listing the shadows in the opposite order would change which one appears on top.

How to tune a shadow

Change one value at a time so you can see what it does. Start with the offsets to position the shadow, then adjust blur for softness, spread for size, and color for contrast. If the effect should appear inside the frame, add inset.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browser support

MDN marks box-shadow as Baseline and widely available, with support across browsers since July 2015. Typical current use does not require historical vendor-prefixed forms. If a project must support very old browsers, check the MDN browser compatibility table against its actual target browsers rather than assuming universal legacy support.

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 *

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.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
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.