Skip to main content

Command Palette

Search for a command to run...

An Easy Guide To The CSS Box-shadow Property.

Updated
β€’2 min read
An Easy Guide To The CSS Box-shadow Property.
A

Hi, I'm Alaa Aldybous 🌸

An Electrical and computer engineering student and a Self-Taught Web developer

I write about:

  • what I learn
  • CSS Art
  • tips & tricks-hacks that I discover throughout my journey
  • Electrical engineering what I learn as a student

Skills:

  • MATLAB
  • C++
  • Python
  • HTML & CSS

I'm learning

  • Python-Django- Flask
  • Arduino

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 😊 https://www.buymeacoffee.com/Alaaanan β˜•

A

Thank you for this article I have referred to it a few times whenever I forget the syntax for box-shadows!

1
A

Your welcome
I'm so glad you found it helpful 😊