All of these box-shadow examples can be copied with a simple click! Use the shadows for your own projects or explore our resources to learn more about CSS techniques.
📌 Press ⌘+D to bookmark this page
It is important to note that CSS box shadows are an excellent way to enhance the “layered” effect of an element and screen. Shadow overlays improve the look of the interface or make it more “active”. The box-shadow
property permits to add further shadows to an element with peculiar offset, blur and spread radius and color.
The box-shadow
property is defined with the following syntax:
Last but not the least is the color of the shadow: box-shadow-color: color
(any CSS color: background-color: rgbValue, rgbaValue, hexValue, etc.).
box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3);
In this example, a self-shadow produces at a distance of 2 pixels on the right side and at a distance of 2 pixels at the bottom while having a blurring distance of 5 pixels and soft black of 30% opacity.
box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.3);
Incorporating the inset
keyword instead changes the shadow from an outer shadow effect to an inner shadow effect making the outer layer look different.
box-shadow: 2px 2px 5px rgba(255, 0, 0, 0.3), 2px 2px 5px rgba(0, 0, 0, 0.1);
To use more than one shadow, you add a comma to do so. In this case, the example creates 2 shadows, one toward the bottom right and the second one toward the top left. This in turn adds to the strength of the shadow.
box-shadow: 0 4px 10px rgba(0,0,0,0.5);
One advantage of using rgba
is that you get to even determine how opaque the shadow will be. This is useful especially if need to make shadow effects that are thin and light on the whether it is a text or images in a background.
.box {
transition: box-shadow 0.3s ease;
}
.box:hover {
box-shadow: 0 4px 20px rgba(0,0,0,.4);
}
You can further enhance the user interactivity of web pages by changing shadow on hover to create dynamic effects.
CSS box shadows are handy tools in helping to make the interfaces of web sites that you are designing more attractive. Playing around with shadow properties will definitely result in more interesting UI. Don’t hesitate to mix shadows with other CSS properties for even greater results!