How to Add Color and Blur Effect to Box-shadow in CSS

When it comes to web design, box-shadows can add a lot of depth and dimension to your layout.

However, the default box-shadow property in CSS only allows you to add a single color and blur effect.

In this tutorial, we’ll show you how to add color and blur effects to your box-shadows using CSS.

First, let’s take a look at the basic syntax for creating a box-shadow.

The box-shadow property is applied to a specific element, and it accepts several values.

These values include the horizontal offset, the vertical offset, the blur radius, the spread distance, and the color of the shadow.

box-shadow: horizontal_offset vertical_offset blur_radius spread_distance color;

Here’s an example of a basic box-shadow:

box-shadow: 10px 10px 5px 0px #000000;

In this example, the horizontal offset is 10px, the vertical offset is 10px, the blur radius is 5px, the spread distance is 0px, and the color is black.

Now, let’s add some color to our box-shadow.

To do this, we’ll use the rgba() function.

The rgba() function allows you to specify the red, green, blue, and alpha values of a color.

The alpha value controls the transparency of the color.

box-shadow: 10px 10px 5px 0px rgba(255, 0, 0, 0.5);

In this example, the color of the shadow is red with 50% transparency.

To add a blur effect to your box-shadow, you can use the filter property.

The filter property allows you to apply various effects to an element, including blur.

filter: blur(5px);

In this example, we’ve applied a blur effect of 5px to the box-shadow.

You can combine the above examples to create a box-shadow with color and blur effect:

box-shadow: 10px 10px 5px 0px rgba(255, 0, 0, 0.5);
filter: blur(5px);

And that’s it! With just a few lines of CSS, you can add color and blur effects to your box-shadows.

In conclusion, box-shadow is a powerful CSS property that can add depth and dimension to your web designs.

With this tutorial, you can now create eye-catching box-shadows with color and blur effects.

Also Read:

How Do I Vertically Center Text With CSS
How to Add a Blur Effect to the Shadow in CSS
How to Add a Button to an Image With CSS
How to Add a Color to the Shadow in CSS
How to Add a Form to a Full-width Image With CSS
How to Add Color to Box-shadow in CSS
How to Add Different Colors to a Hyperlink in CSS
How to Add different colors to visited/unvisited links in CSS
How to Add Rounded Corners to Elements in CSS
How to Add space between an outline and the border of an element in CSS
How to Add White Text With Black Shadow in CSS
How to Align Images Side by Side With CSS
How to Align the text in CSS



Resources and References:

  1. CSS Resources – CSS Portal
  2. CSS: Cascading Style Sheets – MDN Web Docs
  3. CSS Tutorial – W3Schools
  4. CSS – Useful Resources – Tutorialspoint