Box Shadow Generator
Generate CSS box-shadow code with visual preview for drop shadows, inset, and layered effects. Enter values for instant results with step-by-step formulas.
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer
Box Shadow Generator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: box-shadow: [inset] h-offset v-offset blur spread color
Additional inputs: Radius (px).
Worked example โ CSS: box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.15); โ clean elevated card shadow.
Formula
box-shadow: [inset] h-offset v-offset blur spread color
The box-shadow property accepts an optional inset keyword, horizontal offset, vertical offset, blur radius, spread radius, and color. Positive horizontal values move the shadow right, positive vertical values move it down. Blur softens edges and spread expands or contracts the shadow.
Worked Examples
Example 1: Material Design Card Shadow
Problem:Create a subtle shadow for a card component that looks elevated, similar to Material Design elevation level 2.
Solution:Use no horizontal offset, 4px vertical offset, 12px blur, and 0 spread with 15% opacity black. box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.15); The zero horizontal offset keeps the shadow centered. The 4px vertical offset simulates a top-down light source. 12px blur creates a soft, natural gradient at the edges.
Result:CSS: box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.15); โ clean elevated card shadow.
Example 2: Floating Button Shadow
Problem:Create a prominent shadow for a floating action button that appears to hover above the page with significant depth.
Solution:Use 0px horizontal, 10px vertical, 25px blur, and -5px spread with 20% opacity. box-shadow: 0px 10px 25px -5px rgba(0, 0, 0, 0.20); The -5px spread prevents the shadow from extending beyond the button width. The 25px blur creates a very soft, diffused shadow. 10px vertical offset implies the button is significantly elevated.
Result:CSS: box-shadow: 0px 10px 25px -5px rgba(0, 0, 0, 0.20); โ dramatic floating shadow.
Frequently Asked Questions
What is CSS box-shadow and how does it work?
CSS box-shadow adds one or more shadow effects around an element. The property accepts values for horizontal offset, vertical offset, blur radius, spread radius, and color. The horizontal and vertical offsets determine the shadow position relative to the element, with positive values moving right and down respectively. The blur radius controls how soft or sharp the shadow appears, with zero creating a perfectly crisp edge. The spread radius expands or contracts the shadow size before blurring. You can also add the inset keyword to place the shadow inside the element instead of outside. Multiple shadows can be layered by separating them with commas, creating rich depth effects.
How do blur and spread values affect the shadow appearance?
Blur and spread work together to define the shadow shape and softness. The blur radius creates a Gaussian blur effect, where a value of zero produces a sharp-edged shadow identical to the element shape. Larger blur values make the shadow progressively softer and more diffused. The spread radius expands (positive values) or contracts (negative values) the shadow before the blur is applied. A positive spread makes the shadow larger than the element, useful for creating glow effects. A negative spread makes the shadow smaller, which when combined with a vertical offset and large blur, creates realistic elevated shadows. Understanding these two properties independently gives you precise control over shadow aesthetics.
What is the difference between drop-shadow and box-shadow?
Box-shadow and the drop-shadow filter produce similar visual effects but work fundamentally differently. Box-shadow applies a shadow to the rectangular box model of an element, meaning it always creates a rectangular shadow regardless of the element content shape. The drop-shadow CSS filter, on the other hand, respects the alpha channel of the element, creating shadows that follow the actual shape of transparent images or text. Box-shadow also supports the spread radius and inset keyword, which drop-shadow does not. Performance-wise, box-shadow is generally faster because it does not require compositing. For rectangular elements, box-shadow is preferred, while drop-shadow is essential for non-rectangular shapes like PNG images with transparency.
How do I create layered or multiple shadows in CSS?
Multiple shadows are created by separating individual shadow values with commas in a single box-shadow declaration. The first shadow in the list renders on top, with subsequent shadows layered behind it. A common technique is to combine a small, dark, close shadow (for definition) with a larger, lighter, distant shadow (for depth). For example, you might use a 1px offset with 3px blur at high opacity plus a 10px offset with 30px blur at low opacity. This mimics how real-world lighting creates both sharp contact shadows and soft ambient shadows. Many modern design systems use two or three layered shadows to create more realistic elevation effects than a single shadow can achieve.
What are best practices for shadow design in modern web development?
Modern shadow design follows several established principles for realistic and aesthetic results. First, use consistent light source direction across your entire interface, typically from the top or top-left. Second, avoid using pure black shadows; instead use dark colors with low opacity (10-25%) or slightly tinted shadows that match your color scheme. Third, scale shadow properties with elevation: higher elements should have larger offsets, more blur, and lower opacity. Fourth, consider using negative spread values with larger blur for more natural-looking shadows. Fifth, test shadows on both light and dark backgrounds. Sixth, use CSS custom properties for shadow tokens to maintain consistency. Finally, be mindful of performance when applying shadows to many elements simultaneously.
How does the inset keyword change box-shadow behavior?
The inset keyword fundamentally changes where the shadow is rendered, placing it inside the element rather than outside. An inset shadow creates the visual impression that the element is pressed into or carved out of the page surface. The offset values still work the same way, but their visual effect is reversed: a positive vertical offset creates a shadow at the top of the element interior, making it appear lit from below. Inset shadows are commonly used for input fields to create a recessed appearance, toggle switches to show pressed states, and neumorphic design patterns. You can combine inset and regular shadows on the same element by listing them comma-separated, creating complex depth effects.
What shadow values create the most realistic depth effects?
Realistic depth effects mimic how light and shadow behave in the physical world. For a subtle elevation like a card, use small offsets (0-2px vertical), moderate blur (6-12px), and low opacity (10-15%). For medium elevation like dropdowns, increase the offset (4-8px vertical), blur (16-24px), and keep opacity moderate (15-20%). For high elevation like modals, use larger offsets (12-24px vertical), extensive blur (32-48px), and combine with a slight negative spread to prevent the shadow from appearing too large. Google Material Design popularized this approach with defined elevation levels. The key insight is that as elevation increases, shadows become larger, softer, and slightly less opaque, matching how ambient occlusion works in real lighting scenarios.
Can I animate box-shadow with CSS transitions?
Yes, box-shadow is animatable with CSS transitions and keyframe animations, but there are important performance considerations. Adding transition: box-shadow 0.3s ease allows smooth shadow changes on hover or state changes. However, animating box-shadow can be expensive because it triggers repaints on every frame. A performant alternative is to create a pseudo-element with the target shadow, position it behind the element, and animate its opacity instead. This way the browser only needs to composite the opacity change rather than recalculating the shadow geometry each frame. For simple hover effects on a small number of elements, direct box-shadow animation is fine. For complex animations or many elements, the pseudo-element technique is strongly recommended.
How do I convert box-shadow values between design tools and CSS?
Design tools like Figma, Sketch, and Adobe XD use slightly different shadow models than CSS. Figma exports shadows with X offset, Y offset, blur, and spread that map directly to CSS box-shadow values. However, Figma uses a different blur algorithm, so a 10px blur in Figma may look slightly different in the browser. Sketch shadows also map closely but may require opacity adjustment. Adobe XD uses distance and angle instead of X/Y offsets, requiring trigonometric conversion: X = distance times cosine of angle, Y = distance times sine of angle. When copying shadows from design tools, always verify the result in a browser. Color values may also differ between tools, especially regarding alpha channel handling and color space interpretation.
What are neumorphic shadows and how are they created?
Neumorphism is a design trend that creates soft, extruded shapes by combining a light shadow and a dark shadow on a matching background. The technique requires a background color on both the element and its parent, typically a mid-tone gray or muted color. Two shadows are applied: one with a lighter color positioned toward the light source (negative offsets) and one with a darker color positioned away from the light source (positive offsets). For example, on a light gray background, you might use box-shadow with -6px -6px 12px white and 6px 6px 12px with a darker gray. The pressed state reverses these with inset shadows. While visually distinctive, neumorphism has accessibility concerns because low contrast between elements can make interfaces difficult to navigate for users with visual impairments.
References
Background & Theory
History
Reviewed for accuracy by Daniel Agrici, Founder & Lead Developer ยท Editorial policy
Related Calculators
๐งฎColor Palette Generator
Generate harmonious color palettes using complementary, analogous, triadic, and split schemes.
๐งฎGradient Generator
Create CSS gradient code from color stops with linear, radial, and conic options.
๐งฎBorder Radius Generator
Generate CSS border-radius code with visual preview for rounded corners and organic shapes.
๐งฎSubwoofer Box Calculator
Calculate sealed and ported subwoofer enclosure dimensions from driver specifications.
๐งฎDepth of Field Calculator
Calculate depth of field with interactive inputs and clear steps.
๐งฎHyperfocal Distance Calculator
Calculate hyperfocal distance with interactive inputs and clear steps.
๐งฎField of View Calculator (camera)
Calculate field of view (camera) with interactive inputs and clear steps.
๐งฎShutter Speed to Freeze Motion Calculator
Calculate shutter speed to stop motion with interactive inputs and clear steps.