CSS Box Shadow
button {
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.card {
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}
Let me ask you something.
Have you ever noticed that cards on modern websites seem to float slightly above the background? That buttons feel like they have a little bit of weight to them? That certain sections feel closer to you than others?
That feeling of depth is not magic. It is box shadow. And once you understand it, you will see it everywhere.
What is Box Shadow
Box shadow adds a shadow behind an element. It works just like a real shadow — a light source above your element casts a shadow below it, giving the element the illusion of being lifted off the page.
Here is the basic syntax.
box-shadow: offset-x offset-y blur color;
offset-x — how far the shadow moves left or right. Positive values push it right, negative values push it left.
offset-y — how far the shadow moves up or down. Positive values push it down, negative values push it up.
blur — how soft or sharp the shadow is. 0 is a hard shadow. Higher values make it softer and more spread out.
color — the color of the shadow. Usually a dark semi-transparent RGBA value.
Unlimited movies, TV shows, and more.
The card now appears to float slightly above the background. That single line of CSS creates the illusion of depth.
Adjusting the Blur
The blur value is what makes the biggest difference to how a shadow feels. A low blur creates a sharp, dramatic shadow. A high blur creates a soft, subtle glow.
Sharp shadow
Sharp and defined. Now try a higher blur.
Soft shadow
Softer and more spread out. This is the style used on most modern cards — a large blur with a low opacity gives a gentle, realistic shadow.
For most card shadows, aim for a blur between 12px and 32px with an RGBA opacity between 0.08 and 0.2. Shadows that are too dark or too sharp feel dated. Subtle is almost always better.
The Spread Value
There is an optional fourth value before the color — the spread. It controls how large the shadow grows beyond the element itself. Positive spread makes the shadow bigger. Negative spread shrinks it.
box-shadow: offset-x offset-y blur spread color;
Card with spread shadow
The shadow now extends slightly further out from all sides of the card. This is useful when you want the shadow to feel more like a glow than a directional light source.
Shadows on Buttons
Buttons with shadows feel more physical and clickable. They look like something you can actually press.
Notice how the shadow color matches the button color — a semi-transparent red. This is called a colored shadow, and it makes the button feel like it is glowing slightly. You will see this pattern on call-to-action buttons everywhere.
Matching the shadow color to the element color — just more transparent — creates a much more natural and modern look than always using a grey or black shadow. Try it on any colored button or card.
Inset Shadows
Adding the word inset at the start of a box-shadow flips it inside the element instead of outside. This
creates a pressed-in effect rather than a lifted effect.
The input field now looks slightly recessed into the page. This is a subtle but effective way to make form fields feel more tactile and intentional.
Multiple Shadows
You can layer multiple shadows on a single element by separating them with commas. This is how designers create rich, realistic depth effects.
Layered shadow card
The first shadow is small and close — it defines the crisp edge of the element. The second is large and soft — it creates the feeling of elevation. Together they produce a much more natural and polished shadow than a single value ever could.
Building the Netflix Clone
Let us add some depth to our Netflix clone. A shadow on the sign-in button and a subtle lift on the input and submit button will make everything feel more designed.
Netflix
Unlimited movies, TV shows, and more.
Starts at USD 2.99. Cancel anytime.
Ready to watch? Enter your email to create or restart your membership.
* { margin: 0; padding: 0; } body { font-family: "Roboto", Arial, sans-serif; font-size: 16px; padding: 40px; background-image: linear-gradient(to bottom, rgba(0,0,0,0.7), rgba(0,0,0,0.4)), url("https://assets.nflxext.com/ffe/siteui/vlv3/9ba9f0e2-b246-47f4-bd1f-3e84c23a5db8/web/NP-en-20251020-TRIFECTA-perspective_774f89dc-b75d-4cfc-b1fe-52086741fae3_large.jpg"); background-size: cover; background-position: center; background-repeat: no-repeat; text-align: center; } #logo { font-family: "Bebas Neue", sans-serif; font-size: 3rem; font-weight: 700; color: #E50914; letter-spacing: 4px; line-height: 1; margin-bottom: 16px; } h1 { font-family: "Bebas Neue", sans-serif; font-size: 3rem; font-weight: 700; color: white; letter-spacing: 2px; line-height: 1.2; margin: 60px 0 16px 0; } p { font-size: 1.1rem; font-weight: 300; color: white; line-height: 1.6; margin-bottom: 12px; } button { background-color: #E50914; color: white; font-size: 1rem; font-weight: 600; text-transform: uppercase; letter-spacing: 2px; padding: 12px 32px; margin-top: 24px; border: none; border-radius: 4px; box-shadow: 0 4px 16px rgba(229, 9, 20, 0.5); } .signin { background-color: transparent; border: 2px solid white; color: white; font-size: 0.9rem; font-weight: 600; padding: 8px 20px; margin-top: 0; border-radius: 4px; box-shadow: none; } input { border: 2px solid #cccccc; padding: 12px 16px; font-size: 1rem; border-radius: 4px; box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1); }The Get Started button now glows with a red shadow that matches its color. The input has a subtle inset shadow making it feel recessed. Small details, but they push the whole thing closer to a real production design.
Have anything to say about this lesson?
Your feedback helps improve these tutorials. If something was confusing or missing, let us know.