惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
罗磊的独立博客
The GitHub Blog
The GitHub Blog
L
LangChain Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
DataBreaches.Net
宝玉的分享
宝玉的分享
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
美团技术团队
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
CSS box-shadow: The Complete Guide to Multi-Layer Shadows
Snappy Tools · 2026-06-12 · via DEV Community

Snappy Tools

The box-shadow property is one of the most underused tools in CSS. Most developers use it for a single subtle drop shadow and stop there — but the full syntax supports layered shadows, inset effects, and colour-based glows that can replace entire images.

This guide covers everything from the basic syntax to advanced multi-layer techniques.

The full syntax

box-shadow: [inset] offset-x offset-y [blur-radius] [spread-radius] color;

Each part:

  • offset-x — horizontal distance. Positive = right, negative = left.
  • offset-y — vertical distance. Positive = down, negative = up.
  • blur-radius — how soft the edge is. 0 = crisp edge, 20px = soft fade. Cannot be negative.
  • spread-radius — expands (+) or contracts (-) the shadow beyond the element size.
  • color — usually rgba() so you can control opacity.
  • inset — optional keyword that puts the shadow inside the element.

Why rgba() for colour?

Most shadow colours are variations of black with opacity. rgba(0, 0, 0, 0.12) gives you black at 12% opacity — the element behind shows through, making the shadow look natural regardless of background colour.

/* Avoid this — opaque black shadow looks fake */
box-shadow: 0 4px 8px #000000;

/* Do this — transparent shadow works on any background */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.12);

Multiple shadows: the real power

Separate shadows with commas. The first shadow is drawn on top (closest to the element):

.card {
  box-shadow:
    0 1px 3px rgba(0, 0, 0, 0.12),  /* tight shadow for sharpness */
    0 4px 16px rgba(0, 0, 0, 0.08); /* wide shadow for ambient depth */
}

This two-layer pattern is the basis of Material Design's elevation system. Each layer doubles in size while halving in opacity — the result looks like physically accurate depth.

Inset shadows

The inset keyword flips the shadow inside the element. This is perfect for:

  • Buttons in their active/pressed state
  • Input fields with a focus ring
  • Recessed UI surfaces
/* Pressed button effect */
.btn:active {
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Input focus ring */
input:focus {
  box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
}

box-shadow as a border

box-shadow: 0 0 0 2px #2f855a creates a 2px ring identical to a border — but without affecting layout. Unlike outline, it respects border-radius exactly.

Useful for stacking multiple rings:

.card:focus {
  box-shadow:
    0 0 0 2px white,         /* inner white gap */
    0 0 0 4px #2f855a;       /* outer green ring */
}

Glow effects

Zero offset + large blur + saturated colour = glow:

.btn-primary {
  box-shadow:
    0 0 12px rgba(47, 133, 90, 0.5),
    0 0 32px rgba(47, 133, 90, 0.2);
}

Common preset values

Effect CSS
Soft card 0 2px 8px rgba(0,0,0,0.08)
Material card 0 1px 3px rgba(0,0,0,0.12), 0 2px 4px rgba(0,0,0,0.08)
Floating modal 0 8px 24px rgba(0,0,0,0.14), 0 16px 48px rgba(0,0,0,0.08)
Focus ring 0 0 0 3px rgba(66,153,225,0.5)
Pressed inset inset 0 2px 6px rgba(0,0,0,0.2)

Performance note

box-shadow triggers repaint, not reflow. For static use it is fast — most GPUs handle it without any measurable impact. For animated shadows, add will-change: box-shadow or animate via transform + a static shadow on a pseudo-element for smoother 60fps results.


If you want to build shadows visually without writing code, try the CSS Box Shadow Generator — it gives you sliders for every parameter, a live preview card, 5 presets, and copies the complete CSS with one click.