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.
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:
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);
}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);
}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);
}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);
}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);
}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.
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.
rgba() for shadow colors so you can control opacity independently of the element color.filter: drop-shadow() for PNG icons.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.
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.
Use our free online calculators and tools for all your needs.
Browse All 213+ Tools โ