What Are CSS Shadows?
CSS shadows add visual depth around elements or text without changing the element's layout dimensions. They are commonly used to create cards, floating panels, buttons, input states, elevated surfaces, text emphasis, and subtle visual separation.
The two most important shadow features are
box-shadow and
text-shadow.
The first creates shadows around an element's box, while the second creates shadows
around text glyphs.
.card {
box-shadow: 0 10px 30px rgb(0 0 0 / 0.12);
}
.title {
text-shadow: 0 2px 8px rgb(0 0 0 / 0.2);
}
Shadows are presentation effects. They do not normally change the amount of space allocated to an element in normal document layout, which makes them useful for creating depth without pushing neighboring elements around.
What Is box-shadow?
The box-shadow property adds one or more shadows
around an element's box. It is one of the most commonly used CSS properties for creating
visual elevation.
.card {
box-shadow: 0 8px 24px rgb(0 0 0 / 0.12);
}
A standard box shadow is defined using horizontal offset, vertical offset, blur radius, optional spread radius, and color.
</pre>
<p>
Understanding each value makes it much easier to control the appearance instead of
relying on random shadow values copied from other designs.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">What Do the box-shadow Values Mean?</h2>
<p>
A typical <code class="text-cyan-300">box-shadow</code> declaration can be written as:
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
box-shadow: 12px 8px 24px 4px rgb(0 0 0 / 0.15);
}
The values represent:
| Value | Purpose |
|---|---|
| 12px | Horizontal offset |
| 8px | Vertical offset |
| 24px | Blur radius |
| 4px | Spread radius |
| rgb(...) | Shadow color and opacity |
The horizontal and vertical offsets move the shadow. The blur radius controls how much the shadow becomes softened. The optional spread radius expands or contracts the shadow before the blur is applied.
What Is the Horizontal Offset?
The first length in a normal box-shadow declaration
controls the horizontal position of the shadow.
</pre>
<p>
A positive value moves the shadow toward the right, while a negative value moves it
toward the left.
</p>
<p>
A value of <code class="text-cyan-300">0</code> centers the shadow horizontally around
the element.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">What Is the Vertical Offset?</h2>
<p>
The second length controls the vertical position of the shadow.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.down {
box-shadow: 0 12px 20px rgb(0 0 0 / 0.15);
}
.up {
box-shadow: 0 -12px 20px rgb(0 0 0 / 0.15);
}
Positive values move the shadow downward, while negative values move it upward. A zero value keeps the shadow vertically centered around the element.
What Is the Blur Radius?
The blur radius controls how soft the shadow edges become. Larger blur values produce a softer and more spread-out shadow, while smaller values create a sharper shadow.
</pre>
<p>
A large blur does not simply make the shadow darker. It distributes the shadow over
a broader area, making the effect appear softer.
</p>
<p>
Large blur values can be useful for elevated surfaces, while smaller values are often
better for borders, controls, and subtle interaction feedback.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">What Is the Spread Radius?</h2>
<p>
The spread radius changes the size of the shadow before the blur is applied.
A positive value expands the shadow and a negative value contracts it.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.expanded {
box-shadow: 0 8px 20px 6px rgb(0 0 0 / 0.12);
}
.contract {
box-shadow: 0 8px 20px -4px rgb(0 0 0 / 0.12);
}
Spread is useful when you need more control over the apparent footprint of a shadow. It is particularly helpful when creating rings, compact shadows, or tightly controlled card elevation.
What Does Shadow Color and Opacity Do?
The color determines the appearance of the shadow, while alpha transparency controls how strongly the shadow is visible.
</pre>
<p>
Semi-transparent neutral shadows are common in interface design because they create
depth without overpowering the surface underneath.
</p>
<p>
Colored shadows can also be useful when a design system intentionally uses a brand or
accent color as part of the visual language.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.accent {
box-shadow:
0 12px 30px rgb(37 99 235 / 0.22);
}
Be careful with strongly colored shadows. A shadow should usually reinforce the component hierarchy rather than compete with the content.
What Is an Inset Shadow?
Adding the inset keyword changes the shadow from an
outer shadow to an inner shadow. The effect appears inside the element's box.
</pre>
<p>
Inset shadows can create recessed surfaces, pressed controls, input fields, and subtle
inner borders.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.pressed {
box-shadow:
inset 0 3px 8px rgb(0 0 0 / 0.18);
}
You can combine inset and outer shadows in the same declaration.
</pre>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">Can CSS Have Multiple Box Shadows?</h2>
<p>
Yes. Multiple shadows can be separated with commas. They are painted as a stack of
shadow layers, which allows you to create more sophisticated depth effects.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
box-shadow:
0 2px 4px rgb(0 0 0 / 0.06),
0 8px 20px rgb(0 0 0 / 0.08),
0 20px 40px rgb(0 0 0 / 0.06);
}
Multiple subtle shadows can sometimes produce a more natural result than one extremely large shadow. This is useful for premium cards, panels, menus, and elevated surfaces.
The order of multiple shadow layers matters. The first shadow is painted on top of later shadow layers, so changing their order can change the final visual appearance.
How Do You Create a Card Elevation System?
Instead of inventing a different shadow for every component, a design system can define a small set of elevation levels.
</pre>
<p>
This creates a consistent relationship between surfaces. A simple card does not need the
same elevation as a modal or floating navigation menu.
</p>
<p>
Naming shadows by semantic level rather than by raw implementation details can make a
design system easier to maintain.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">What Is text-shadow?</h2>
<p>
The <code class="text-cyan-300">text-shadow</code> property creates one or more shadows
behind text glyphs. Its basic syntax is similar to box-shadow, but it does not support
the spread-radius or <code class="text-cyan-300">inset</code> features of
<code class="text-cyan-300">box-shadow</code>.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.title {
text-shadow:
0 2px 6px rgb(0 0 0 / 0.2);
}
Text shadows are useful for headings over photographs, subtle typography depth, decorative titles, and certain display effects.
</pre>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">How Does text-shadow Syntax Work?</h2>
<p>
A typical text shadow contains horizontal offset, vertical offset, optional blur radius,
and color.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.heading {
text-shadow:
2px 3px 8px rgb(0 0 0 / 0.25);
}
The first value moves the shadow horizontally, the second moves it vertically, and the optional blur value controls softness.
Multiple text shadows can also be combined.
</pre>
<p>
Multiple text shadows can create glowing or outlined-looking effects, but readability
should remain the priority for normal interface text.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">What Is the Difference Between box-shadow and text-shadow?</h2>
<div class="overflow-x-auto rounded-xl border border-slate-800">
<table class="min-w-full text-left text-sm">
<thead class="bg-slate-900 text-white">
<tr>
<th class="px-4 py-3">Feature</th>
<th class="px-4 py-3">box-shadow</th>
<th class="px-4 py-3">text-shadow</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-800">
<tr>
<td class="px-4 py-3 text-slate-200">Shadow target</td>
<td class="px-4 py-3">Element box</td>
<td class="px-4 py-3">Text glyphs</td>
</tr>
<tr>
<td class="px-4 py-3 text-slate-200">Blur</td>
<td class="px-4 py-3">Supported</td>
<td class="px-4 py-3">Supported</td>
</tr>
<tr>
<td class="px-4 py-3 text-slate-200">Spread radius</td>
<td class="px-4 py-3">Supported</td>
<td class="px-4 py-3">Not part of text-shadow syntax</td>
</tr>
<tr>
<td class="px-4 py-3 text-slate-200">Inset</td>
<td class="px-4 py-3">Supported</td>
<td class="px-4 py-3">Not supported</td>
</tr>
<tr>
<td class="px-4 py-3 text-slate-200">Typical use</td>
<td class="px-4 py-3">Cards, panels, controls</td>
<td class="px-4 py-3">Headings and decorative text</td>
</tr>
</tbody>
</table>
</div>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">What Is filter: drop-shadow()?</h2>
<p>
CSS also provides <code class="text-cyan-300">filter: drop-shadow()</code>.
It is related to shadows but works differently from
<code class="text-cyan-300">box-shadow</code>.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.icon {
filter: drop-shadow(0 8px 12px rgb(0 0 0 / 0.18));
}
A box shadow follows the element's box shape, while a drop shadow is generated from the rendered alpha shape of the element. This difference becomes useful for transparent images, icons, SVG artwork, and irregular silhouettes.
</pre>
<p>
For a transparent PNG with a non-rectangular subject, a drop shadow can follow the visible
shape more naturally than a normal box shadow.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">When Should You Use box-shadow Instead of drop-shadow()?</h2>
<p>
Use <code class="text-cyan-300">box-shadow</code> when the shadow should represent the
rectangular or rounded box of a component.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
box-shadow: 0 12px 28px rgb(0 0 0 / 0.12);
}
Use drop-shadow() when the visual shape itself matters.
This is particularly helpful for irregular transparent artwork and icons.
</pre>
<p>
The two properties are not interchangeable. Choosing the one that matches the visual
object usually produces a more natural result.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">Do CSS Shadows Affect Layout?</h2>
<p>
Shadows are visual effects and do not normally increase an element's layout size.
A box can have a large shadow while still occupying the same layout dimensions.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
width: 300px;
padding: 1.5rem;
box-shadow: 0 30px 60px rgb(0 0 0 / 0.2);
}
This means a shadow can visually extend into nearby areas without pushing neighboring elements away. However, large shadows can visually overlap other components, so spacing and stacking should still be considered when designing the interface.
How Do Shadows Work with Border Radius?
A box shadow generally follows the shape of the element's border box, including rounded
corners created with border-radius.
</pre>
<p>
The rounded surface and its shadow therefore work naturally together for card and panel
designs.
</p>
<p>
Remember that the shadow itself does not automatically clip child content to the rounded
corners. That behavior is controlled separately by clipping and overflow rules.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">How Do You Create a Subtle Card Shadow?</h2>
<p>
A professional card shadow usually needs low opacity and enough blur to create depth
without looking like a dark outline.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
border: 1px solid #e2e8f0;
border-radius: 1rem;
background: white;
box-shadow:
0 4px 12px rgb(15 23 42 / 0.06);
}
The border provides a precise edge while the soft shadow creates separation from the surrounding surface. This combination is common in modern interface systems.
How Do You Create a Hover Shadow?
Shadows can be combined with transitions to communicate that a component is interactive.
</pre>
<p>
Keep the movement and shadow change relatively small. The goal is to indicate interaction,
not make the component appear to jump dramatically out of the page.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">How Do You Create an Inset Input Effect?</h2>
<p>
Inset shadows can make an input appear slightly recessed into its surrounding surface.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.input {
border: 1px solid #cbd5e1;
border-radius: 0.75rem;
box-shadow:
inset 0 2px 6px rgb(15 23 42 / 0.08);
}
You can combine this with a visible focus state so that the input remains understandable when a user navigates with a keyboard.
</pre>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">Can Shadows Be Animated?</h2>
<p>
Yes. <code class="text-cyan-300">box-shadow</code> and
<code class="text-cyan-300">text-shadow</code> can participate in CSS transitions and
animations. However, shadow rendering can be more computationally expensive than some
simpler properties, especially when many large or complex shadows are animated.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
box-shadow:
0 4px 12px rgb(0 0 0 / 0.06);
transition:
box-shadow 200ms ease;
}
.card:hover {
box-shadow:
0 18px 36px rgb(0 0 0 / 0.14);
}
For large-scale motion, animating transform and
opacity is often a better starting point, with
shadows used as a supporting visual effect rather than the primary animated property.
How Do CSS Variables Help with Shadow Systems?
Custom properties are useful for creating a consistent shadow scale across a project.
</pre>
<p>
This makes the visual hierarchy predictable and gives a design system a central place
to adjust shadow strength later.
</p>
<p>
Shadow variables can also change between light and dark themes.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code::root {
--surface-shadow:
0 12px 30px rgb(15 23 42 / 0.10);
}
[data-theme="dark"] {
--surface-shadow:
0 16px 34px rgb(0 0 0 / 0.35);
}
.card {
box-shadow: var(--surface-shadow);
}
How Should Shadows Be Used in Dark Mode?
Shadows that look subtle on a light background do not always have the same visual effect on a dark background. Because there is less contrast between a dark shadow and a dark surface, simply reusing the same shadow can produce little visible separation.
Dark interfaces often combine subtle shadows with border colors, surface-color differences, or carefully controlled darker layers to communicate hierarchy.
</pre>
<p>
The most reliable approach is to test the actual component on the final surface rather
than assuming that one shadow value works equally well in every theme.
</p>
</section>
<section class="space-y-5">
<h2 class="text-2xl font-bold text-white">Can Shadows Replace Borders?</h2>
<p>
Sometimes a shadow can provide enough separation that a border is unnecessary, but the
two properties communicate slightly different visual ideas.
</p>
<p>
A border creates a precise boundary. A shadow suggests depth and separation from another
surface. Many component systems use both, especially when a subtle border defines the
edge and a soft shadow communicates elevation.
</p>
<pre class="overflow-x-auto rounded-xl bg-slate-900 p-5 text-sm text-slate-200"><code:.card {
border: 1px solid #e2e8f0;
box-shadow:
0 8px 24px rgb(15 23 42 / 0.08);
}
The best choice depends on the visual hierarchy you want to create. Do not add both automatically just because many design systems do.
Common CSS Shadow Mistakes
Using extremely dark shadows
High-opacity black shadows can make modern interfaces look heavy and outdated. Softer alpha values usually produce a more natural depth effect.
Using huge blur values everywhere
Very large shadows can visually wash out neighboring components and add unnecessary rendering work when used extensively.
Adding shadows to every element
Excessive elevation destroys hierarchy because every component appears equally important.
Using box-shadow for irregular shapes
Transparent icons and irregular artwork may look better with filter: drop-shadow().
Relying only on shadows for focus
Keyboard focus should have a clear, intentional indicator and should not disappear because the shadow is subtle.
Animating many large shadows
Large animated shadows can be expensive. Use motion properties carefully and profile complex interfaces.
Best Practices for CSS Shadows
Create a small elevation scale
Use a few meaningful shadow levels instead of inventing a unique value for every component.
Use transparency thoughtfully
Semi-transparent shadows usually blend more naturally with different surfaces.
Match the shadow to the hierarchy
Floating dialogs should generally have stronger visual separation than ordinary cards.
Choose drop-shadow for irregular shapes
filter: drop-shadow() can better follow the alpha shape of transparent artwork.
Test shadows on actual backgrounds
A shadow can look completely different on white, gray, and dark surfaces.
Keep accessibility ahead of decoration
Never let a decorative shadow replace important focus, state, or content indicators.
Final Takeaway
CSS shadows provide a simple way to create depth, separation, and visual emphasis.
The primary tool for surfaces and components is box-shadow,
while text-shadow is designed for text and
filter: drop-shadow() is useful when the shadow should
follow the visible shape of rendered content.
The most important box-shadow concepts are horizontal
offset, vertical offset, blur radius, spread radius, color, and the optional
inset keyword. Multiple shadows can then be layered
to create a controlled elevation system.
Good shadow design is about hierarchy, not decoration. Use subtle shadows where they improve separation or communicate elevation, keep your values consistent through design tokens, and avoid making every component appear to float.