CSS box-shadow Property
The box-shadow property adds one or more shadows around or inside an element's box.
Each shadow can have horizontal and vertical offsets, a blur radius, a spread radius, and a color. By default, shadows appear outside the element, but the inset keyword places them inside.
Box shadows are commonly used to add depth to cards, buttons, panels, and other interface components. They follow an element's border radius and do not affect its layout dimensions.
box-shadow Syntax
Set the box-shadow property using at least two length values for the horizontal and vertical offsets.
selector {
box-shadow: 4px 6px 12px rgb(0 0 0 / 25%);
}
The general syntax for an individual shadow is:
selector {
box-shadow: [inset] <offset-x> <offset-y> [blur-radius] [spread-radius] [color];
}
The optional inset keyword and color may appear in different positions within a shadow declaration. Multiple shadows are separated by commas.
Basic Shadow
.box {
box-shadow: 4px 4px;
}
Shadow with Blur
.box {
box-shadow: 4px 6px 12px #888888;
}
Shadow with Spread
.box {
box-shadow: 4px 6px 12px 3px rgb(0 0 0 / 25%);
}
Inset Shadow
.box {
box-shadow: inset 0 2px 6px rgb(0 0 0 / 25%);
}
Multiple Shadows
.box {
box-shadow: 0 2px 4px rgb(0 0 0 / 15%), 0 8px 20px rgb(0 0 0 / 10%);
}
No Shadow
.box {
box-shadow: none;
}
CSS-Wide Keywords
.inherited {
box-shadow: inherit;
}
.reset {
box-shadow: initial;
}
.unset {
box-shadow: unset;
}
.reverted {
box-shadow: revert;
}
.layer-reverted {
box-shadow: revert-layer;
}
Each shadow requires two offsets. The blur radius, spread radius, color, and inset keyword are optional.
Property Values
The box-shadow property accepts the following components:
| Value | Description |
|---|---|
none |
Removes all box shadows. This is the initial value. |
offset-x |
Required horizontal offset. Positive values move the shadow right, and negative values move it left. |
offset-y |
Required vertical offset. Positive values move the shadow down, and negative values move it up. |
blur-radius |
Optional non-negative length controlling shadow softness. Defaults to zero. |
spread-radius |
Optional length that expands or contracts the shadow. Defaults to zero. |
color |
Optional shadow color. If omitted, the shadow uses currentcolor. |
inset |
Changes an outer shadow into an inner shadow. |
| Comma-separated shadows | Allows multiple shadows to be applied to the same element. |
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Inherits the computed shadow list from the parent. |
initial |
Resets the property to none. |
unset |
Resets the property to none because it is not inherited. |
revert |
Reverts the property according to cascade origin rules. |
revert-layer |
Reverts the property according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Initial value | none |
| Inherited | No |
| Applies to | All elements |
| Computed value | none or a list of shadows with computed lengths, colors, and inset status |
| Animation type | Shadow list |
| Percentages | Not accepted for shadow dimensions |
| Negative offsets | Allowed |
| Negative blur radius | Not allowed |
| Negative spread radius | Allowed |
| Affects layout size | No |
The shadow is a visual effect. It does not increase the element's width, height, or space reserved in document flow.
How It Works
A box shadow is generated from the element's border box. Its shape follows the element's border radius, if one is specified.
Step 1: Create an Element
<div class="shadow-card">
<h3>Card Title</h3>
<p>This card has a soft shadow.</p>
</div>
Step 2: Add Basic Styling
.shadow-card {
padding: 20px;
border-radius: 8px;
background-color: #ffffff;
}
Step 3: Add a Shadow
.shadow-card {
box-shadow: 0 4px 12px rgb(0 0 0 / 20%);
}
The horizontal offset is zero, the vertical offset is 4 pixels, and the blur radius is 12 pixels.
Step 4: Add Spread
.shadow-card {
box-shadow: 0 4px 12px 3px rgb(0 0 0 / 20%);
}
The positive spread radius expands the shadow's shape before blurring.
Step 5: Add an Inner Shadow
.shadow-card {
box-shadow: inset 0 2px 6px rgb(0 0 0 / 20%);
}
The shadow now appears inside the element instead of outside it.
Step 6: Combine Shadows
.shadow-card {
box-shadow: 0 4px 12px rgb(0 0 0 / 15%), inset 0 1px 3px rgb(0 0 0 / 10%);
}
The element now has both an outer shadow and an inset shadow.
The browser paints box shadows as part of the element's visual decoration, without changing its layout dimensions.
Horizontal Offset
The first length value controls the shadow's horizontal position.
Shadow to the Right
.box {
box-shadow: 10px 0 8px rgb(0 0 0 / 25%);
}
A positive horizontal offset moves the shadow to the right.
Shadow to the Left
.box {
box-shadow: -10px 0 8px rgb(0 0 0 / 25%);
}
A negative horizontal offset moves the shadow to the left.
Centered Horizontally
.box {
box-shadow: 0 6px 12px rgb(0 0 0 / 25%);
}
A zero horizontal offset keeps the shadow centered horizontally before blur and spread are applied.
Combined Horizontal and Vertical Offset
.box {
box-shadow: 8px 6px 12px rgb(0 0 0 / 25%);
}
The shadow moves right and down.
Horizontal offsets accept CSS length units such as px, rem, and em.
Vertical Offset
The second length value controls the shadow's vertical position.
Shadow Below
.box {
box-shadow: 0 10px 8px rgb(0 0 0 / 25%);
}
A positive vertical offset moves the shadow downward.
Shadow Above
.box {
box-shadow: 0 -10px 8px rgb(0 0 0 / 25%);
}
A negative vertical offset moves the shadow upward.
Centered Shadow
.box {
box-shadow: 0 0 12px rgb(0 0 0 / 25%);
}
Zero horizontal and vertical offsets produce a shadow centered around the box.
Diagonal Shadow
.box {
box-shadow: 6px 8px 12px rgb(0 0 0 / 25%);
}
The shadow moves right and down.
Vertical offsets can be positive, negative, or zero.
Blur Radius
The optional third length value controls the softness of the shadow.
No Blur
.box {
box-shadow: 6px 6px 0 #777777;
}
A blur radius of zero produces a sharp shadow edge.
Small Blur
.box {
box-shadow: 6px 6px 4px rgb(0 0 0 / 25%);
}
Medium Blur
.box {
box-shadow: 6px 6px 12px rgb(0 0 0 / 25%);
}
Large Blur
.box {
box-shadow: 6px 6px 24px rgb(0 0 0 / 25%);
}
Larger blur radii generally create softer, more diffuse shadows.
Omitted Blur
.box {
box-shadow: 6px 6px #777777;
}
When the blur radius is omitted, it defaults to zero.
Invalid Negative Blur
/* Invalid: negative blur radius */
.box {
box-shadow: 6px 6px -4px #777777;
}
Negative blur radii are invalid and cause the declaration to be ignored.
The blur radius describes the blur effect, not the exact distance that the visible shadow extends.
Spread Radius
The optional fourth length value controls how much the shadow's shape expands or contracts before blurring.
Positive Spread
.box {
box-shadow: 0 4px 10px 5px rgb(0 0 0 / 20%);
}
A positive spread radius expands the shadow.
Negative Spread
.box {
box-shadow: 0 4px 10px -5px rgb(0 0 0 / 20%);
}
A negative spread radius contracts the shadow.
Zero Spread
.box {
box-shadow: 0 4px 10px 0 rgb(0 0 0 / 20%);
}
Sharp Outline Effect
.box {
box-shadow: 0 0 0 4px #1769aa;
}
With zero offsets and blur, a positive spread creates a sharp ring around the box.
Subtle Bottom Shadow
.box {
box-shadow: 0 8px 12px -8px rgb(0 0 0 / 30%);
}
A negative spread can help concentrate the visible shadow near one edge.
Large Spread
.box {
box-shadow: 0 0 0 12px rgb(23 105 170 / 20%);
}
Large positive spread values can create halos or layered border effects.
The spread radius is optional and defaults to zero.
Shadow Colors
Box shadows accept CSS color values, including named colors, hexadecimal colors, RGB, HSL, and currentcolor.
Hexadecimal Color
.box {
box-shadow: 0 4px 10px #777777;
}
RGB with Transparency
.box {
box-shadow: 0 4px 12px rgb(0 0 0 / 20%);
}
HSL Color
.box {
box-shadow: 0 4px 12px hsl(210 60% 40% / 30%);
}
Named Color
.box {
box-shadow: 0 4px 10px steelblue;
}
currentcolor
.box {
color: #1769aa;
box-shadow: 0 0 0 3px currentcolor;
}
The shadow uses the element's current text color.
Omitted Color
.box {
color: #1769aa;
box-shadow: 0 0 0 3px;
}
When the shadow color is omitted, it defaults to currentcolor.
Transparent Shadow
.box {
box-shadow: 0 4px 12px transparent;
}
The shadow is transparent and therefore not visible.
Partially transparent colors generally produce softer, more natural-looking shadows than fully opaque colors.
Outer Shadows
Outer shadows are the default. They appear outside the element's border box and are painted behind the element.
Basic Outer Shadow
.card {
box-shadow: 0 4px 12px rgb(0 0 0 / 20%);
}
Soft Outer Shadow
.card {
box-shadow: 0 8px 24px rgb(0 0 0 / 12%);
}
Sharp Outer Shadow
.card {
box-shadow: 6px 6px 0 #1769aa;
}
Centered Glow
.card {
box-shadow: 0 0 18px rgb(23 105 170 / 45%);
}
Bottom-Weighted Shadow
.card {
box-shadow: 0 10px 18px -8px rgb(0 0 0 / 30%);
}
Large Floating Shadow
.card {
box-shadow: 0 16px 40px rgb(0 0 0 / 18%);
}
Outer shadows can make elements appear elevated above their surrounding content.
They do not change the box's dimensions or reserve additional space around the element.
Inset Shadows
The inset keyword changes a shadow from an outer shadow to an inner shadow.
Basic Inset Shadow
.box {
box-shadow: inset 0 2px 6px rgb(0 0 0 / 25%);
}
Inset Shadow on All Sides
.box {
box-shadow: inset 0 0 10px rgb(0 0 0 / 20%);
}
Inset Border Effect
.box {
box-shadow: inset 0 0 0 2px #1769aa;
}
Pressed Button
.button:active {
box-shadow: inset 0 3px 6px rgb(0 0 0 / 25%);
}
Recessed Input
.form-input {
padding: 10px;
border: 1px solid #cccccc;
box-shadow: inset 0 2px 4px rgb(0 0 0 / 10%);
}
Inner Highlight
.panel {
box-shadow: inset 0 2px 0 rgb(255 255 255 / 70%);
}
Inset shadows are drawn inside the element's padding edge, above the background and below its content.
They are useful for recessed controls, pressed states, inner borders, and subtle highlights.
Multiple Shadows
The box-shadow property accepts a comma-separated list of shadows.
Two Outer Shadows
.card {
box-shadow: 0 2px 4px rgb(0 0 0 / 12%), 0 10px 24px rgb(0 0 0 / 10%);
}
Three Outer Shadows
.card {
box-shadow: 0 1px 2px rgb(0 0 0 / 10%), 0 4px 8px rgb(0 0 0 / 10%), 0 12px 24px rgb(0 0 0 / 8%);
}
Outer and Inset Shadows
.card {
box-shadow: 0 6px 16px rgb(0 0 0 / 18%), inset 0 1px 3px rgb(0 0 0 / 10%);
}
Layered Border Effect
.box {
box-shadow: 0 0 0 3px #ffffff, 0 0 0 6px #1769aa;
}
Multiple Colored Rings
.box {
box-shadow: 0 0 0 4px #1769aa, 0 0 0 8px #7bb9e8, 0 0 0 12px #d8ecfa;
}
Shadow Painting Order
Shadows are painted front to back. The first shadow in the list appears above later shadows of the same type.
Outer shadows are painted behind the element, while inset shadows are painted inside the element. Their painting positions remain distinct even when both types appear in the same list.
Removing Multiple Shadows
.box {
box-shadow: none;
}
The none value removes the complete shadow list.
Multiple subtle shadows often produce a more natural sense of depth than one large, dark shadow.
Box Shadows and Border Radius
Box shadows follow the shape of an element's border box, including rounded corners created with border-radius.
Rounded Card
.card {
border-radius: 12px;
box-shadow: 0 6px 18px rgb(0 0 0 / 18%);
}
Circular Element
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
box-shadow: 0 4px 12px rgb(0 0 0 / 25%);
}
Pill-Shaped Button
.pill-button {
padding: 10px 24px;
border-radius: 999px;
box-shadow: 0 4px 10px rgb(0 0 0 / 20%);
}
Different Corner Radii
.card {
border-radius: 4px 20px 4px 20px;
box-shadow: 0 6px 16px rgb(0 0 0 / 20%);
}
Inset Shadow with Rounded Corners
.panel {
border-radius: 12px;
box-shadow: inset 0 0 0 3px #1769aa;
}
The shadow shape follows the rounded border geometry rather than remaining a sharp rectangle.
Box shadows do not follow the visible alpha shape of a transparent image. For shadows that follow an image's nontransparent outline, consider filter: drop-shadow().
Shadows, Borders, and Outlines
Box shadows can resemble borders or outlines, but they behave differently.
Border
.box {
border: 3px solid #1769aa;
}
A border contributes to the element's box dimensions under the applicable box-sizing rules.
Shadow Ring
.box {
box-shadow: 0 0 0 3px #1769aa;
}
The shadow ring is painted outside the box without affecting layout dimensions.
Outline
.box {
outline: 3px solid #1769aa;
}
An outline does not occupy layout space and is commonly used to indicate keyboard focus.
Border and Shadow Together
.card {
border: 1px solid #dddddd;
box-shadow: 0 4px 12px rgb(0 0 0 / 12%);
}
Focus Ring with box-shadow
.button:focus-visible {
outline: 2px solid #1769aa;
outline-offset: 3px;
box-shadow: 0 0 0 5px rgb(23 105 170 / 20%);
}
The outline provides a clear focus indicator, while the shadow adds a secondary visual effect.
Do not remove keyboard focus indicators solely to replace them with subtle shadows that may be difficult to see.
box-shadow vs. drop-shadow()
Both box-shadow and the CSS drop-shadow() filter can create shadows, but they use different shapes and rendering methods.
| Feature | box-shadow | drop-shadow() |
|---|---|---|
| Shadow shape | Element's border box | Rendered alpha shape |
| Inset shadows | Supported | Not supported |
| Spread radius | Supported | Not supported |
| Multiple shadows | Comma-separated list | Multiple filter functions |
| Common use | Cards and interface boxes | Transparent images and irregular shapes |
Box Shadow
.image {
box-shadow: 0 6px 12px rgb(0 0 0 / 25%);
}
Drop Shadow Filter
.image {
filter: drop-shadow(0 6px 12px rgb(0 0 0 / 25%));
}
For a transparent PNG image, box-shadow follows the rectangular image element's box, while drop-shadow() can follow the visible image content.
Multiple Drop Shadows
.image {
filter: drop-shadow(0 3px 5px rgb(0 0 0 / 20%)) drop-shadow(0 8px 12px rgb(0 0 0 / 10%));
}
Choose box-shadow for ordinary element boxes and drop-shadow() when the shadow should follow an irregular visible shape.
Layout and Overflow
Box shadows are visual decorations and do not affect the element's layout dimensions.
Shadow Does Not Add Width
.box {
width: 200px;
padding: 20px;
box-shadow: 0 0 0 10px #1769aa;
}
The shadow does not increase the element's calculated box width.
Shadow Does Not Add Height
.box {
height: 100px;
box-shadow: 0 12px 20px rgb(0 0 0 / 25%);
}
The shadow does not reserve additional vertical space.
Clipped Shadows
.container {
overflow: hidden;
}
.card {
box-shadow: 0 8px 20px rgb(0 0 0 / 25%);
}
The shadow may be clipped where it extends outside the container's clipping area.
Allowing Visible Overflow
.container {
overflow: visible;
}
.card {
box-shadow: 0 8px 20px rgb(0 0 0 / 25%);
}
Spacing Between Cards
.card-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 24px;
}
.card {
box-shadow: 0 8px 16px rgb(0 0 0 / 15%);
}
Grid gaps provide space between the cards so their shadows are less likely to overlap visually.
Box Sizing
.card {
box-sizing: border-box;
width: 250px;
padding: 20px;
box-shadow: 0 6px 18px rgb(0 0 0 / 20%);
}
The box-sizing property affects how width and height include padding and borders, but box shadows remain outside those calculations.
Allow enough spacing around shadowed elements, especially when using large blur or spread values.
Transitions and Animation
The box-shadow property supports transitions and animations between compatible shadow lists.
Hover Shadow
.card {
box-shadow: 0 2px 6px rgb(0 0 0 / 12%);
transition: box-shadow 0.3s ease;
}
.card:hover {
box-shadow: 0 10px 24px rgb(0 0 0 / 20%);
}
Button Hover
.button {
box-shadow: 0 3px 8px rgb(0 0 0 / 18%);
transition: box-shadow 0.2s ease;
}
.button:hover {
box-shadow: 0 6px 14px rgb(0 0 0 / 25%);
}
Focus Shadow
.input {
box-shadow: 0 0 0 0 rgb(23 105 170 / 0%);
transition: box-shadow 0.2s ease;
}
.input:focus-visible {
outline: 2px solid #1769aa;
box-shadow: 0 0 0 4px rgb(23 105 170 / 20%);
}
Keyframe Animation
@keyframes shadow-pulse {
0%, 100% {
box-shadow: 0 0 0 0 rgb(23 105 170 / 30%);
}
50% {
box-shadow: 0 0 0 12px rgb(23 105 170 / 0%);
}
}
.pulse {
animation: shadow-pulse 2s ease-in-out infinite;
}
Animating Multiple Shadows
.card {
box-shadow: 0 2px 4px rgb(0 0 0 / 10%), 0 8px 16px rgb(0 0 0 / 8%);
transition: box-shadow 0.3s ease;
}
.card:hover {
box-shadow: 0 4px 8px rgb(0 0 0 / 15%), 0 14px 28px rgb(0 0 0 / 12%);
}
Inset and Outer Shadow Animation
Shadow lists containing matching inset and outer shadow types can interpolate their lengths and colors. If corresponding shadows have incompatible inset status, interpolation may be discrete.
Reduced Motion Preference
@media (prefers-reduced-motion: reduce) {
.card,
.button,
.pulse {
transition: none;
animation: none;
}
}
Large animated shadows can require additional painting work. Use restrained effects and test performance on lower-powered devices.
CSS Custom Properties
CSS custom properties can store reusable shadow values and help maintain consistent visual depth across components.
Shared Shadow
:root {
--card-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}
.card {
box-shadow: var(--card-shadow);
}
Multiple Shadow Levels
:root {
--shadow-small: 0 2px 4px rgb(0 0 0 / 12%);
--shadow-medium: 0 6px 16px rgb(0 0 0 / 15%);
--shadow-large: 0 12px 30px rgb(0 0 0 / 20%);
}
.card {
box-shadow: var(--shadow-medium);
}
.dialog {
box-shadow: var(--shadow-large);
}
Fallback Shadow
.card {
box-shadow: var(--card-shadow, 0 4px 12px rgb(0 0 0 / 15%));
}
Custom Shadow Color
:root {
--shadow-color: rgb(0 0 0 / 18%);
}
.card {
box-shadow: 0 6px 18px var(--shadow-color);
}
Component Shadow Override
.card {
--shadow: 0 4px 12px rgb(0 0 0 / 15%);
box-shadow: var(--shadow);
}
.card.featured {
--shadow: 0 10px 24px rgb(0 0 0 / 22%);
}
Reusable shadow values make it easier to apply a consistent elevation system throughout a website.
Responsive Design
Shadow size, blur, and spread can be adjusted for different screen sizes and interface layouts.
Media Query
.card {
box-shadow: 0 10px 24px rgb(0 0 0 / 18%);
}
@media (max-width: 600px) {
.card {
box-shadow: 0 4px 10px rgb(0 0 0 / 12%);
}
}
Container Query
.card-container {
container-type: inline-size;
}
.card {
box-shadow: 0 3px 8px rgb(0 0 0 / 12%);
}
@container (min-width: 500px) {
.card {
box-shadow: 0 10px 24px rgb(0 0 0 / 18%);
}
}
Responsive Blur
.card {
box-shadow: 0 6px clamp(8px, 2vw, 24px) rgb(0 0 0 / 18%);
}
Removing Shadows on Small Screens
.panel {
box-shadow: 0 6px 18px rgb(0 0 0 / 15%);
}
@media (max-width: 480px) {
.panel {
box-shadow: none;
}
}
Dark Color Scheme
.card {
background-color: #ffffff;
box-shadow: 0 6px 18px rgb(0 0 0 / 15%);
}
@media (prefers-color-scheme: dark) {
.card {
background-color: #252525;
box-shadow: 0 6px 18px rgb(0 0 0 / 45%);
}
}
Shadows may need different opacity or contrast on dark backgrounds to remain visible.
Use shadows to support visual hierarchy without making essential information depend on shadow effects alone.
Practical Uses
The box-shadow property is commonly used for cards, buttons, forms, panels, dialogs, and other interface components.
Card Elevation
.card {
padding: 20px;
border-radius: 10px;
background-color: #ffffff;
box-shadow: 0 6px 18px rgb(0 0 0 / 15%);
}
Floating Button
.floating-button {
border-radius: 50%;
box-shadow: 0 8px 20px rgb(0 0 0 / 25%);
}
Dialog Window
.dialog {
padding: 24px;
border-radius: 12px;
background-color: #ffffff;
box-shadow: 0 18px 48px rgb(0 0 0 / 25%);
}
Navigation Dropdown
.dropdown-menu {
background-color: #ffffff;
box-shadow: 0 8px 20px rgb(0 0 0 / 18%);
}
Inset Form Control
.form-control {
border: 1px solid #cccccc;
box-shadow: inset 0 2px 4px rgb(0 0 0 / 10%);
}
Pressed Button
.button:active {
box-shadow: inset 0 3px 6px rgb(0 0 0 / 25%);
}
Colored Glow
.glow {
box-shadow: 0 0 16px rgb(23 105 170 / 50%);
}
Layered Shadow
.card {
box-shadow: 0 2px 4px rgb(0 0 0 / 10%), 0 8px 20px rgb(0 0 0 / 12%);
}
Inset Border
.panel {
box-shadow: inset 0 0 0 2px #1769aa;
}
Use subtle shadows for everyday interface depth and stronger shadows when an element needs to appear more prominent.
box-shadow Example
The following example compares several common box shadow effects, including soft, sharp, spread, inset, and layered shadows.
<div class="shadow-demo">
<div class="demo-box soft">Soft Shadow</div>
<div class="demo-box sharp">Sharp Shadow</div>
<div class="demo-box spread">Spread Shadow</div>
<div class="demo-box inset">Inset Shadow</div>
<div class="demo-box layered">Layered Shadow</div>
<div class="demo-box glow">Colored Glow</div>
</div>
.shadow-demo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
gap: 36px;
padding: 20px 10px;
}
.shadow-demo .demo-box {
display: flex;
align-items: center;
justify-content: center;
min-height: 110px;
padding: 15px;
border-radius: 10px;
background-color: #ffffff;
color: #173b5e;
font-weight: 600;
text-align: center;
}
.shadow-demo .soft {
box-shadow: 0 6px 18px rgb(0 0 0 / 18%);
}
.shadow-demo .sharp {
box-shadow: 6px 6px 0 #1769aa;
}
.shadow-demo .spread {
box-shadow: 0 0 0 6px rgb(23 105 170 / 25%);
}
.shadow-demo .inset {
box-shadow: inset 0 3px 10px rgb(0 0 0 / 22%);
}
.shadow-demo .layered {
box-shadow: 0 2px 4px rgb(0 0 0 / 12%), 0 10px 24px rgb(0 0 0 / 15%);
}
.shadow-demo .glow {
box-shadow: 0 0 18px rgb(23 105 170 / 55%);
}
The examples demonstrate how offsets, blur, spread, color, and inset positioning produce different shadow effects.
All six boxes retain their normal layout dimensions because box shadows do not contribute to the box model's calculated width or height.
Important Considerations
Keep the following points in mind when using box-shadow:
- Purpose: Adds one or more outer or inner shadows to an element.
- Initial value:
none. - Inheritance: The property is not inherited.
- Required values: Every shadow requires horizontal and vertical offsets.
- Horizontal offset: Positive values move right, and negative values move left.
- Vertical offset: Positive values move down, and negative values move up.
- Blur radius: Optional, non-negative, and defaults to zero.
- Spread radius: Optional, accepts negative values, and defaults to zero.
- Shadow color: Optional and defaults to
currentcolor. - Inset: Places the shadow inside the element.
- Multiple shadows: Separate shadows with commas.
- Painting order: Earlier shadows appear above later shadows of the same type.
- Border radius: Shadows follow rounded border-box corners.
- Layout: Shadows do not affect element dimensions or document flow.
- Overflow: Shadows may be clipped by ancestor overflow settings.
- Percentages: Not valid for shadow offsets, blur, or spread.
- Animation: Compatible shadow lists can be interpolated.
- Performance: Large or frequently animated shadows can increase painting work.
- Accessibility: Shadows should not be the only indication of focus or an important interface state.
- Browser support: Widely available in modern browsers without vendor prefixes.
Use box-shadow to create visual depth, subtle borders, inner highlights, and layered effects without changing an element's layout size.
Browser Support
The box-shadow property is widely available and supported in Chrome, Edge, Firefox, Safari, and other major browsers.
Modern browsers support outer shadows, inset shadows, multiple shadows, blur, spread, and shadow colors without vendor prefixes.
.card {
box-shadow: 0 6px 18px rgb(0 0 0 / 18%);
}
This declaration creates a soft outer shadow and works in modern browsers.
Older browser versions may have required vendor-prefixed declarations, but they are generally unnecessary for current browser targets.
For current compatibility details, visit Can I Use? .
Specifications
The box-shadow property is defined in the CSS Backgrounds and Borders Module Level 3 specification.
CSS Backgrounds and Borders Module Level 3
The specification defines shadow syntax, offsets, blur and spread behavior, colors, inset shadows, multiple shadows, and painting order.
