CSS Shadows 🎯

beginner
21 min

CSS Shadows 🎯

Welcome to the CSS Shadows tutorial, where we'll delve into this powerful tool that adds depth and visual interest to your web designs!

Understanding CSS Shadows 📝

CSS shadows, also known as box-shadow, allow you to apply multiple types of shadows to your HTML elements:

  1. inset - Creates an inner shadow.
  2. outset - Creates an outer shadow.

Let's explore how to use these shadows to enhance our web projects! 💡

Basic Box-Shadow Syntax 💡

The CSS box-shadow property accepts up to four values, which define the horizontal offset, vertical offset, blur radius, and shadow color, respectively:

css
.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:

  1. Horizontal offset: 4px (moves the shadow 4 pixels to the right)
  2. Vertical offset: 4px (moves the shadow 4 pixels down)
  3. Blur radius: 6px (softens the edges of the shadow)
  4. Shadow color: rgba(0, 0, 0, 0.3) (sets the shadow color to a semi-transparent black)

Inset Shadows 💡

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:

css
.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.

Multiple Box-Shadows 💡

You can also apply multiple box-shadow properties to create complex shadow effects:

css
.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.

Real-World Application 💡

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.

Quiz 📝

Quick Quiz
Question 1 of 1

What does the `box-shadow` property do?

Quick Quiz
Question 1 of 1

What is an inset shadow?