In this article you will get to know about smooth CSS Shadows and a easy way to use them. But first of all
What are shadows?
When light falls upon an object shadow is formed. The shadows we see around us works on the same principle but they are really complex and realistic as they are not in a specific shape or length or size. They can take any shape and can fall in any direction. In order to create shadows in websites using CSS we use box-shadow
property.
for ex. box-shadow: 0 10px 10px rgba(0, 0, 0, 0.1);
But if you are trying to create real shadows through box-shadow
property, well, You can't.
Why?
In order to know 'Why?' you have to understand how box-shadow property works.
box-shadow
property simply produces a blurred silhouette of an object. You can change its length, color, blur, spread and offset nothing more. Then there's probably no way to create the Natural Super complex real Shadows through box-shadow
property.
But unexpectedly there's a way!
If we will use a simple technique, we will be able to get more controls and expand our range of options. This technique is using 'layered shadows'. We can define multiple shadows in a simple box-shadow
property by using commas and gradually increasing the blur-radius, offset to make shadows more realistic. Here's an example:
As you can see the difference in shadows. You can customize it more to generate more variants of shadows i.e. Sharp shadows, Dreamy shadows, long shadows etc.
/* Normal box-shadow */
.box {
box-shadow: 0 3px 3px rgba(0,0,0,0.2);
}
/* Layered Box-shadow */
box-shadow:
0 3.9px 4.6px rgba(0, 0, 0, 0.08),
0 12.3px 8.4px rgba(0, 0, 0, 0.056),
0 18.8px 19.2px rgba(0, 0, 0, 0.037),
0 22px 40px rgba(0, 0, 0, 0.019)
;
More Layers == More Customization == More Realistic shadows
You can also generate Sharp shadows by gradually decreasing the alpha values (opacity) and increasing the blur strength to create Sharp shadows. You can use the same principle to create Diffused shadows.
We can also create Short as well as long shadows by just playing with opacity and spread. To create long shadows we can gradually increase the y-offset values.
However creating these kind of shadows is a real mess for some people, specifically for those people and for making our life more easy there is website which can help them in Creating realistic shadows i.e. https://shadows.brumm.af/ by Philipp.
Through this website you can create as many layers as you want and edit them in real time, Saving a lot of time and efforts.
A post by Devang. Hope it helps!
Check out my portfolio: here
Top comments (13)
I was trying to figure out how to do a dumbed-down mixin for layered drop-shadows a while back, I'd love to see how you put together the generator if you're willing to share. I get it if not, a lot of calculations going on there.
Thanks for sharing with the community, lovely generator you've built!
You're welcome. And about the generator it isn't made by me😅 it is built by brumm.af/
I forgot to give him credits.
can you please remove the JS tag since your post is only related to CSS?
Done! and Sorry i did that for getting more views😅
doing that may get you the opposite effect because someone following the JS tag may not be intrested in CSS posts. You have more tags you can use that are more relevant than JS
Oh I didn't knew that thanks for your Feedback😊
Nice read! Thanks for sharing🤙🏻
Exactly what I needed! Thanks!
I have also found this:
https://neumorphism.io/
Great peice of article
Very cool tool, thanks for the helpful info!
I am a tremendous fan of Layered box shadows. This approach allows me to create masterworks by combining multiple shades. Thanks for providing outstanding new ideas in your realistic shadows guide.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.