How to Add Color to Box-shadow in CSS

Adding color to box-shadow in CSS is a great way to enhance the visual appeal of a website.

It can add depth, dimension, and emphasis to a particular element on the page.

In this CSS tutorial, we will explore how to add color to box-shadow in CSS and provide code examples to help you implement it on your own website.

Introduction

Box-shadow is a CSS property that allows you to add a shadow effect to an element on the page.

By default, the shadow is black, but you can change the color of the shadow by using the “color” property.

This can be done by adding the “color” property to the box-shadow property, as well as specifying a color value.


How to Add Color to Box-shadow

The basic syntax for the box-shadow property is as follows:

box-shadow: offset-x offset-y blur-radius spread-radius color;

To add color to the box-shadow, you will need to add the color property after the spread-radius value.

For example, to add a red shadow to an element, you would use the following code:

box-shadow: 0px 0px 10px 0px red;

The above code would add a red shadow with an offset of 0 pixels in both the x and y direction, a blur radius of 10 pixels, and no spread radius.

You can also specify the color value in the following ways:

  1. Using a named color:
box-shadow: 0px 0px 10px 0px blue;
  1. Using a hex color code:
box-shadow: 0px 0px 10px 0px #0000FF;
  1. Using an RGB color value:
box-shadow: 0px 0px 10px 0px rgb(0,0,255);
  1. Using an RGBA color value:
box-shadow: 0px 0px 10px 0px rgba(0,0,255,0.5);

In the last example, the “a” in “rgba” stands for “alpha” which can be used to adjust the transparency of the color.

Multiple Box-shadows

You can also add multiple box-shadows to an element by separating them with a comma. For example, the following code would add a red and a blue shadow to an element:

box-shadow: 0px 0px 10px 0px red, 0px 0px 20px 0px blue;

Conclusion

Adding color to box-shadow in CSS is a simple and effective way to enhance the visual appeal of a website.

By using the color property, you can change the default black color of the shadow and create unique and interesting effects on your website.

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