An Easy Guide To The CSS Box-shadow Property.

An Easy Guide To The CSS Box-shadow Property.

I'm making this article for beginners that are new to box-shadow. To me, it took me some time to get the hang of it.

So let's start with box-shadow syntax. โœ

box-shadow: X-Axis Y-Axis  Blur Spreed (here the color of the shadow)

X-Axis

When you add a value to the X-Axis you move the shadow along the X-axis Example:

  • giving it a positive value will move the shadow to the Right
  • giving it a negative value will move the shadow to the Left

x-axis.png

โ˜๏ธ For visualization if you are a visual learning like me ๐Ÿ˜

Y-Axis

When you add a value to the Y-Axis you move the shadow along the Y-axis Example:

  • giving it a positive value will move the shadow to the Up
  • giving it a negative value will move the shadow to the Down

y-axis.png

Blur

Blur gives the shadow that soft edge.

The higher the value you give the softer the edges get and the box-shadow color will blend even more with the background which leads to spreading the color and lowering the opacity.

here are some examples:

A Smaller value:

box-shadow: 0 0 10px 0 gray;

capture_20220119202522375.bmp

A Higher value:

box-shadow: 0 0 70px 0 gray;

capture_20220119202501124.bmp

Spread

Spread increase the size of the shadow.

Example:

box-shadow: 0 0 0 7px gray;

capture_20220119201531712.bmp

The shadow is the gray border around the pink circle

The value I gave it was 7px, if I gave it a higher number I will get a wider border.

The edges of the border would be harsh if we didn't give the blur any value.

box-shadow: 0 0 13px 7px gray;

capture_20220119201726225.bmp

Tips ๐Ÿช„

you can use box-shadow to duplicate an element ๐Ÿคฏ

instead of making two divs and styling both of them, you could just make a box-shadow where the blur and spread values are zero then you could move the shadow using the x-axis and y-axis.

capture_20220119203414306.bmp

The lavender circle is the shadow I gave it the color lavender is to show you which one is the shadow though I could have made them the same color if I want a certain effect.

And that's it Hope this article was helpful. ๐Ÿฅฐ

If it was helpful I hope you would consider buying me coffee ๐Ÿ˜Š buymeacoffee.com/Alaaanan โ˜•

ย