DEV Community

Ruxin Qu
Ruxin Qu

Posted on • Updated on

CSS: Add shadow

1.Applies a drop shadow effect to the image.

img{
  filter: drop-shadow(offset-x offset-y blur color);
}
Enter fullscreen mode Exit fullscreen mode

example:
filter: drop-shadow(1px 1px 1px black);

add shadow to an img


2.Add shadow to the text.

h1{
  text-shadow: offset-x offset-y blur color;
}
Enter fullscreen mode Exit fullscreen mode

An example from www.w3schools.com:
text-shadow: 5px 5px 10px red;
add shadow to the text


3.Add one or more rectangle shape shadow to an element

  box-shadow: offset-x offset-y blur color, 
              offset-x offset-y blur color, 
              offset-x offset-y blur color;
}
Enter fullscreen mode Exit fullscreen mode

An example from www.w3schools.com:
box-shadow: 5px 5px 8px blue, 10px 10px 8px red, 15px 15px 8px green;
multiple shadow with blur effect


*Difference between box-shadow and drop-shadow

Breaking down CSS Box Shadow vs. Drop Shadow

Top comments (0)