agyanadda@gmail.com

CSS Shadows

Advanced CSS 1 min read Updated Dec 1, 2026 Topic 33 of 39

box-shadow

box-shadow: 0 4px 12px rgba(0,0,0,0.15);

Values in order: x-offset, y-offset, blur, spread (optional), colour.

  • inset puts the shadow inside the box
  • Separate several shadows with commas

text-shadow

text-shadow: 2px 2px 4px gray; — x, y, blur, colour.

Soft shadows with low opacity look more modern than dark, hard ones.

Example

Example — Card shadows HTML
<style>
  body { background: #f4f6fa; }
  .card { background: white; padding: 20px; margin: 16px 0; border-radius: 10px; transition: box-shadow .2s; }
  .soft { box-shadow: 0 4px 12px rgba(0,0,0,.12); }
  .soft:hover { box-shadow: 0 10px 24px rgba(0,0,0,.2); }
  .inset { box-shadow: inset 0 2px 6px rgba(0,0,0,.2); }
  h2 { text-shadow: 1px 2px 3px rgba(0,0,0,.3); color: #1f386b; }
</style>

<h2>Shadows</h2>
<div class="card soft">Soft shadow (hover me)</div>
<div class="card inset">Inset shadow</div>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which keyword puts a box-shadow inside the element?

Exercise 2 True / False

You can add more than one shadow by separating them with commas.

Exercise 3 Fill in the Blank

The third value in box-shadow: 0 4px 12px black; is the ___.

Frequently Asked Questions

No. Shadows are drawn visually and do not take up space or move other elements.