[css] How can I add a box-shadow on one side of an element?

clip-path is now (2020) one of simplest ways to achieve box-shadows on specific sides of elements, especially when the required effect is a "clean cut" shadow at particular edges (which I believe was what the OP was originally looking for) , like this:

_x000D_
_x000D_
.shadow-element {_x000D_
    border: 1px solid #333;_x000D_
    width: 100px;_x000D_
    height: 100px;_x000D_
    box-shadow: 0 0 15px rgba(0,0,0,0.75);_x000D_
    clip-path: inset(0px -15px 0px 0px);_x000D_
}
_x000D_
<div class="shadow-element"></div>
_x000D_
_x000D_
_x000D_

...as opposed to an attenuated/reduced/thinning shadow like this:

_x000D_
_x000D_
.shadow-element {_x000D_
    border: 1px solid #333;_x000D_
    width: 100px;_x000D_
    height: 100px;_x000D_
    box-shadow: 15px 0px 15px -10px rgba(0,0,0,0.75);_x000D_
}
_x000D_
<div class="shadow-element"></div>
_x000D_
_x000D_
_x000D_

Simply apply the following CSS to the element in question:

box-shadow: 0 0 Xpx [hex/rgba]; /* note 0 offset values */
clip-path: inset(Apx Bpx Cpx Dpx);

Where:

  • Apx sets the shadow visibility for the top edge
  • Bpx right
  • Cpx bottom
  • Dpx left

Enter a value of 0 for any edges where the shadow should be hidden and a negative value (the same as the box-shadow blur radius - Xpx) to any edges where the shadow should be displayed.