CSS shadows are used to add depth, focus, and style to both text and box elements. With just a few values, you can make headings glow, cards float above the page, or buttons feel more clickable and modern.
In this topic, you’ll learn how to use:
inset shadows).#000) or smooth alpha color (e.g. rgba()).text-shadow applies to text only, while box-shadow applies to any box element like <div>, <button>, or <section>.
/* Basic syntax for text and box shadows */
text-shadow: horizontal-offset vertical-offset blur-radius color;
box-shadow: horizontal-offset vertical-offset blur-radius spread-radius color;
Example with real values:
/* Simple dark shadow behind text */
text-shadow: 2px 2px 4px #000000;
/* Soft outer shadow around a card */
box-shadow: 5px 5px 15px 0px rgba(0, 0, 0, 0.3);
/* Neon-style glowing heading */
h1.glow-title {
color: #ffffff;
background-color: #111827;
padding: 16px;
text-align: center;
text-shadow: 0 0 6px #22d3ee,
0 0 12px #22d3ee,
0 0 24px #22d3ee;
}
/* Card with soft, modern shadow */
.card {
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
}
/* Layered / retro-style text shadow */
.heading-multi {
font-size: 2rem;
text-shadow: 1px 1px 0 #000000,
3px 3px 4px rgba(0, 0, 0, 0.4);
}
/* Inner shadow to create pressed effect */
.box-inset {
background-color: #e5f4ff;
padding: 18px;
border-radius: 10px;
box-shadow: inset 2px 2px 8px rgba(0, 0, 0, 0.2);
}
Here, the text looks slightly raised and clearer because of a soft dark shadow behind it.
The box-shadow around this box gives it an elevated “card” look, as if it’s above the page.
By changing the color to a bright accent, the shadow adds a colorful, dramatic effect to the text.
With the inset keyword, the shadow moves inside the element, creating a pressed or sunken style.
rgba() colors for smoother blending, e.g. rgba(0, 0, 0, 0.25).:hover to make buttons and cards feel interactive.inset with box-shadow to create inner depth, especially for input fields or panels.box-shadow becomes stronger on :hover.inset shadow to appear pressed into the page.