Box Shadow Property

Last updated: 2026-09-13

box-shadow Box Shadow Property

The box-shadow property adds one or more shadow layers around or inside an element's border box, giving the element depth and hierarchy on the page. It is a core property for modern UI effects such as floating cards and pressed buttons, and supports offset, blur radius, spread radius, and color.

Category
Initial Valuenone
InheritedNo
Applies Toall
Animation Typeshadow
CSS VersionCSS3
StatusStandard

📝 Syntax

box-shadow: none | <shadow>#;
/* <shadow> = inset? && <length>{2,4} && <color>? */

⚙️ Values

ValueTypeDescription
noneKeywordNo box shadow
<shadow>#TypeA shadow list: inset? horizontal vertical blur spread color

▶ Example

Edit the code below and see the live result in the playground:

🌐 Browser Support

Browser ChromeChrome EdgeEdge FirefoxFirefox SafariSafari OperaOpera
box-shadow v10 v12 v3.5 v5.1 v10.5
Supported in all major browsers
Tip: The first two length values (horizontal and vertical offset) are required. The blur radius and spread radius default to 0, and the color defaults to the element's current text color.
Tip: The inset keyword draws the shadow inside the element, which is commonly used for pressed or recessed states.

❓ FAQ

QWhat is the difference between box-shadow and text-shadow in CSS?
Abox-shadow applies to the whole box model: the shadow follows the outline of the element's border box (including border-radius), producing a rectangular or rounded-rectangular drop. text-shadow applies only to the text itself, casting a shadow along the letterforms. Their syntax is similar — offset, blur, and color — but the affected object and the way they layer are completely different.
QHow do I write multiple box-shadow layers on one single element?
ASeparate multiple shadow sets with commas; the first set is rendered on top. For example, box-shadow: 0 2px 4px #000, 0 8px 16px #333; draws the first layer and then stacks the second one on top. Multiple shadows are often used to simulate the decay of a real shadow or to combine glow and outline effects — the more layers, the closer to real lighting.
QCan box-shadow be animated and why does the box-shadow animation jank?
Abox-shadow supports transitions and animations, but animating it triggers repaint and can stutter on low-end devices. To optimize: only switch the shadow value on hover instead of animating the whole element; use a pseudo-element carrying the shadow and fade it with transition: opacity; or, for critical cases, use filter: drop-shadow(). Always test on the target devices.
QHow do I create an inset box-shadow for a recessed or pressed effect?
APut the inset keyword at the very front of the shadow value and the shadow is cast inside the element — for example, box-shadow: inset 0 2px 8px rgba(0,0,0,0.3). Inset shadows are typically used for pressed buttons and recessed input fields. Multiple inset shadows can be comma-separated and combined into a 3D indented look.

📚 Related Tutorials

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏