CSS Box Shadow Generator Tutorial — Examples and Tips
Box shadows add depth and hierarchy to any web interface. A well-placed shadow can make a card appear to float, highlight an active button, or create a neon glow effect. Instead of memorizing the syntax, use a box shadow generator to visually design your shadows and copy the CSS instantly. This tutorial covers the syntax, common patterns, and practical examples.
Understanding the Box Shadow Syntax
The box-shadow property accepts six values in a specific order:
box-shadow: [inset] offsetX offsetY blurRadius spreadRadius color;Here is what each value does:
- inset (optional): Turns the shadow inward for an embossed effect.
- offsetX: Horizontal offset. Positive moves shadow right, negative left.
- offsetY: Vertical offset. Positive moves shadow down, negative up.
- blurRadius: Higher values create a softer, more diffused shadow. 0 means a sharp edge.
- spreadRadius: Positive expands the shadow, negative shrinks it.
- color: The shadow color, usually defined with rgba for opacity control.
Common Box Shadow Examples
Soft Card Shadow
This is the most common shadow for cards and panels — a subtle, soft drop shadow:
.card {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}Material Design Elevation
Google's Material Design uses layered shadows for depth. A level-2 elevation looks like this:
.elevated {
box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}Inset / Inner Shadow
Adding the inset keyword creates a shadow inside the element, useful for inputs and wells:
.input-field {
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15);
}Neon Glow Effect
For a glowing button effect, use a colored shadow with zero offset:
.neon-btn {
box-shadow: 0 0 10px rgba(79, 70, 229, 0.8), 0 0 20px rgba(79, 70, 229, 0.5);
}Layered Shadows for Realism
A single shadow can look flat. Layering two or three shadows with increasing blur creates a more natural, atmospheric depth:
.floating-card {
box-shadow:
0 1px 2px rgba(0,0,0,0.07),
0 2px 4px rgba(0,0,0,0.07),
0 4px 8px rgba(0,0,0,0.07),
0 8px 16px rgba(0,0,0,0.07);
}Animated Shadows and Transitions
Shadows can be animated on hover to create interactive feedback. A common pattern is increasing the shadow depth on hover to simulate the element lifting off the page:
.card {
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
transition: box-shadow 0.3s ease;
}
.card:hover {
box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}Keep the transition duration short — 0.2 to 0.3 seconds feels responsive. Longer durations make the effect feel sluggish. Also note that animating box-shadow triggers repaints, so for performance-critical elements consider using filter: drop-shadow() instead, which can be GPU-accelerated.
Box Shadow vs. Filter Drop Shadow
The box-shadow property creates a shadow based on the element's box, including border radius. The filter: drop-shadow() function follows the actual shape of the content, including transparent areas of PNG images. Use box-shadow for rectangular elements and drop-shadow for irregular shapes like icons and logos with transparency.
Tips for Better Shadows
- Always use
rgba()for shadow colors so you can control opacity independently of the element color. - Keep shadows subtle — a 0.05 to 0.15 opacity range works for most light backgrounds.
- On dark backgrounds, use lighter-colored shadows with low opacity instead of black.
- Remember that shadows can impact performance if overused on animated elements; prefer
filter: drop-shadow()for PNG icons. - Test shadows on both light and dark themes to ensure they read well.
Using a Box Shadow Generator
Manually tweaking six values across multiple shadows is slow. Our free box shadow generator lets you adjust all parameters with sliders, preview the result live, and copy the exact CSS code when you are happy with the look.
Conclusion
Box shadows are one of the simplest ways to add polish and depth to a UI. By understanding the syntax and using a visual generator, you can create professional-looking shadows in minutes. Try the box shadow generator on ToolsOfIndia.com for your next project.
Try Our Free Tools
Use our free online calculators and tools for all your needs.
Browse All 213+ Tools →What do readers ask most about this guide?
What is the CSS box-shadow syntax?
The box-shadow property takes values in this order: horizontal offset, vertical offset, blur radius, spread radius, and color. For example box-shadow: 2px 4px 8px 0px rgba(0,0,0,0.2);
How do I create an inner box shadow in CSS?
Add the inset keyword at the start of the box-shadow value, such as box-shadow: inset 0 2px 8px rgba(0,0,0,0.3); to create an inner shadow effect.