Welcome to the CSS Shadows tutorial, where we'll delve into this powerful tool that adds depth and visual interest to your web designs!
CSS shadows, also known as box-shadow, allow you to apply multiple types of shadows to your HTML elements:
inset - Creates an inner shadow.outset - Creates an outer shadow.Let's explore how to use these shadows to enhance our web projects! 💡
The CSS box-shadow property accepts up to four values, which define the horizontal offset, vertical offset, blur radius, and shadow color, respectively:
.element {
box-shadow: 4px 4px 6px rgba(0, 0, 0, 0.3);
}In the example above, the box-shadow property has been applied to a class named .element. The four values in the property correspond to:
4px (moves the shadow 4 pixels to the right)4px (moves the shadow 4 pixels down)6px (softens the edges of the shadow)rgba(0, 0, 0, 0.3) (sets the shadow color to a semi-transparent black)Inset shadows are used to create inner shadows that make elements look sunken or embossed. The box-shadow property accepts the inset keyword to create an inset shadow:
.element {
box-shadow: inset 4px 4px 6px rgba(255, 255, 255, 0.1);
}In this example, the shadow is moved inward (negative horizontal and vertical offsets) to create an inset shadow effect.
You can also apply multiple box-shadow properties to create complex shadow effects:
.element {
box-shadow:
0 4px 6px rgba(0, 0, 0, 0.3),
inset 4px 4px 6px rgba(255, 255, 255, 0.1);
}In the example above, two separate box-shadow properties have been combined to create a mix of outer and inset shadows.
Shadows can significantly improve the visual appeal of your web projects. For example, you can use them to create buttons, hover effects, or even make complex designs look more polished.
What does the `box-shadow` property do?
What is an inset shadow?