Skip to content

Blog

CSS box shadow on the bottom only (and in Tailwind)

Frank Spin10 min read

To put a box shadow on the bottom of an element only, give the shadow a downward offset and a negative spread that is as large as the blur: box-shadow: 0 8px 6px -6px rgb(0 0 0 / 0.2);. The negative spread pulls the shadow in on all four sides, so the blur no longer reaches past the left, right and top edges, and the offset pushes what is left out below the element. In Tailwind CSS v4 the same shadow is shadow-[0_8px_6px_-6px_rgb(0_0_0/0.2)].

Below: why this works, how to pick the numbers, how Tailwind's own shadow-* classes behave (they are not bottom-only), a clip-path method for hard edges, and the two things that usually hide a shadow you did add. Every number in the tables below was measured in Chromium 156, pixel by pixel, on a 200 × 100 px white box. The Tailwind classes were compiled with Tailwind CSS 4.3.3.

0 4px 6px
all sides

0 8px 6px -6px
bottom only

shadow-lg
mostly bottom, sides too

The same white box with three shadows. Only the middle one stays off the sides.

The bottom-only box shadow#

A box-shadow takes up to four lengths: horizontal offset, vertical offset, blur and spread, followed by a color.

/*          x   y    blur spread  color */
box-shadow: 0   8px  6px  -6px    rgb(0 0 0 / 0.2);

The browser starts with a copy of the element's box. The spread grows or shrinks that copy on every side, the offsets move it, and the blur softens its edges. The blur reaches roughly its own length past the edge of the copy. Without a spread, a 6px blur always shows about 6px of shadow on the sides, whatever the offset.

With a spread of -6px the copy starts 6px smaller than the element on every side. The 6px blur then only grows it back to the element's own edges, so nothing shows on the left, right or top. The 8px vertical offset moves the copy down. 8px minus the 6px it was shrunk leaves 2px below the element, and the blur adds 6px more, for about 8px of visible shadow at the bottom.

This is what we measured in the middle of each side, counting pixels that are at least one shade darker than the white background:

box-shadowTopSidesBottom
0 4px 6px rgb(0 0 0 / .2)2px6px10px
0 8px 6px -6px rgb(0 0 0 / .2)008px
0 6px 6px -4px rgb(0 0 0 / .2)02px8px
0 12px 12px -12px rgb(0 0 0 / .35)03px, barely visible15px

The third row is the usual mistake: a spread (-4px) smaller than the blur (6px) leaves a thin line of shadow on both sides. The last row shows that with a large blur the far tail of the blur can still darken the sides by one or two shades. Nobody sees that on a white page. If you want it at exactly zero, make the spread a few pixels larger than the blur or lower the opacity. We did not measure those variants.

Picking the numbers

  • Spread: the negative of the blur, or slightly more. 6px blur, -6px spread.
  • Vertical offset: a little more than the spread. The visible depth is about offset + spread + blur, so 8 − 6 + 6 = 8px.
  • Color: black at 10 to 25% opacity. Most examples here use 20%.

A few combinations that work, from subtle to strong:

box-shadow: 0 4px 3px -3px rgb(0 0 0 / 0.15);    /* hairline, for list rows and tabs */
box-shadow: 0 8px 6px -6px rgb(0 0 0 / 0.2);     /* cards and sticky headers */
box-shadow: 0 12px 12px -12px rgb(0 0 0 / 0.35); /* deeper, for a header over a photo */

If you'd rather drag sliders, the box shadow generator shows the shadow on a real card and gives you the CSS and the Tailwind class. Set the spread to minus the blur and you get the same result.

Top, left and right shadows#

The same trick works for any single side. Keep the blur and the negative spread, and move the offset toward the side you want.

SideCSSTailwind v4
Bottom0 8px 6px -6px rgb(0 0 0 / .2)shadow-[0_8px_6px_-6px_rgb(0_0_0/0.2)]
Top0 -8px 6px -6px rgb(0 0 0 / .2)shadow-[0_-8px_6px_-6px_rgb(0_0_0/0.2)]
Right8px 0 6px -6px rgb(0 0 0 / .2)shadow-[8px_0_6px_-6px_rgb(0_0_0/0.2)]
Left-8px 0 6px -6px rgb(0 0 0 / .2)shadow-[-8px_0_6px_-6px_rgb(0_0_0/0.2)]

We measured the top and right versions too: 8px on their own side and 0 on the other three. A top shadow suits a bottom bar or a cookie banner; a right shadow suits a sidebar that sits over the content.

For two opposite sides, combine two shadows with a comma. Top and bottom:

box-shadow: 0 8px 6px -6px rgb(0 0 0 / 0.2), 0 -8px 6px -6px rgb(0 0 0 / 0.2);

In Tailwind CSS#

Tailwind's default shadow-* classes all have a downward offset, and most have a small negative spread, so they look heavier at the bottom. Apart from shadow-2xs, a hard 1px line (0 1px, no blur), they are not bottom-only. This is how far each one reaches on our test box:

ClassValue in v4TopSidesBottom
shadow-sm0 1px 3px 0, 0 1px 2px -1px2px3px4px
shadow-md0 4px 6px -1px, 0 2px 4px -2px1px5px9px
shadow-lg0 10px 15px -3px, 0 4px 6px -4px1px11px21px
shadow-xl0 20px 25px -5px, 0 8px 10px -6px018px38px
shadow-2xl0 25px 50px -12px15px38px65px

All colors are black at 10% (25% for shadow-2xl). For a shadow that stays off the sides you need your own value. There are two ways to add one.

An arbitrary value

Write the CSS value inside brackets, with underscores where the spaces go:

<div class="bg-white shadow-[0_8px_6px_-6px_rgb(0_0_0/0.2)]">...</div>

Tailwind 4.3.3 compiles that to:

.shadow-\[0_8px_6px_-6px_rgb\(0_0_0\/0\.2\)\] {
  --tw-shadow: 0 8px 6px -6px var(--tw-shadow-color, rgb(0 0 0/0.2));
  box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow),
    var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);
}

The color sits in a var(--tw-shadow-color, ...) fallback, so a color class still overrides it. shadow-[0_8px_6px_-6px_rgb(0_0_0/0.2)] shadow-indigo-500/30 gives you the same shape in indigo. Leave the color out entirely (shadow-[0_8px_6px_-6px]) and it falls back to currentcolor, which is your text color at full strength. Add a color class like shadow-black/20 in that case.

A reusable class with @theme

If you use the shadow in more than one place, give it a name in your CSS:

@import "tailwindcss";

@theme {
  --shadow-bottom: 0 8px 6px -6px rgb(0 0 0 / 0.2);
}

That creates a shadow-bottom class that works like the built-in ones, including hover:shadow-bottom and color classes:

<header class="sticky top-0 z-40 bg-white shadow-bottom">...</header>

We checked the output: it is the same rule as the arbitrary value, with .shadow-bottom as the selector.

A hard edge with clip-path#

The negative-spread shadow fades out toward the corners, because the shadow is narrower than the element. Sometimes you want a shadow that runs the full width and stops dead at the sides, like under a sticky header that touches both edges of the screen. Then use a normal shadow and cut off everything except the bottom with clip-path:

.header {
  box-shadow: 0 0 12px rgb(0 0 0 / 0.3);
  clip-path: inset(0 0 -24px 0);
}

inset() takes top, right, bottom and left. Zero on three sides cuts the shadow off at the element's own edge there. The negative bottom value lets the clip area reach 24px below the element so the shadow can show. Make that number at least as large as the shadow. In our measurement this gave 0px on top and sides and 14px at the bottom.

In Tailwind you can keep a built-in shadow and add the clip as an arbitrary property:

<header class="sticky top-0 z-40 bg-white shadow-lg [clip-path:inset(0_0_-30px_0)]">...</header>

With shadow-lg that measured 21px at the bottom and 0 everywhere else.

The catch: clip-path clips everything in the element, not only the shadow. A dropdown menu or a focus ring that sticks out of the header is cut off too. If your header has menus that open below it, use the negative-spread shadow instead, or put the shadow on a separate element behind the header.

An inset shadow at the bottom#

For a shadow inside the element along its bottom edge, the trick is the same with inset and the offset flipped. This is useful on a scrolling list, to hint that more content sits below:

box-shadow: inset 0 -8px 6px -6px rgb(0 0 0 / 0.2);

In Tailwind v4 inset shadows have their own utility, so they can sit next to a normal shadow on the same element:

<ul class="max-h-80 overflow-y-auto inset-shadow-[0_-8px_6px_-6px_rgb(0_0_0/0.2)]">...</ul>

The inset shadow is drawn under the list's content, so list items with their own background will cover it.

When the shadow does not show#

Two things hide a box shadow that is set correctly.

A parent with overflow: hidden. The shadow is drawn outside the element's box, and a parent with overflow-hidden (also overflow-auto and overflow-scroll) clips it. Add some padding to the parent, at least as much as the shadow's depth, or move overflow-hidden to a wrapper further out.

The next element covers it. A bottom shadow falls on top of whatever comes next. If that next element has its own background, the browser paints that background over the shadow, because it comes later in the page. Give the element with the shadow position: relative and a z-index (relative z-10 in Tailwind) so it is painted on top. In our test two white blocks stacked on top of each other showed no shadow at all between them; with relative z-10 on the first one the shadow came back.

A sticky header with a bottom shadow#

A common use, with everything above put together:

<header class="sticky top-0 z-40 bg-white shadow-[0_8px_6px_-6px_rgb(0_0_0/0.2)]">
  <nav class="mx-auto flex max-w-6xl items-center justify-between px-6 py-4">
    ...
  </nav>
</header>

sticky top-0 keeps it at the top, z-40 keeps the content that scrolls under it from covering the shadow, and bg-white stops the content from showing through. For a frosted glass version, swap bg-white for bg-white/70 backdrop-blur-md; the Tailwind filter and backdrop-blur guide explains when that blur works and when it doesn't.

Shadows on images with transparent backgrounds are a different problem. box-shadow always follows the rectangle of the element, so a PNG of a shoe gets a square shadow. Use filter: drop-shadow() (drop-shadow-* in Tailwind) for those; it follows the visible pixels but has no spread, so the bottom-only trick does not work with it.

FAQ#

How do I add a box shadow only on the bottom in CSS?

Use a positive vertical offset and a negative spread equal to the blur: box-shadow: 0 8px 6px -6px rgb(0 0 0 / 0.2);. The negative spread keeps the blur off the top and sides, and the offset moves the shadow below the element.

Why is my bottom shadow still showing on the sides?

The spread is smaller than the blur. With 0 6px 6px -4px we measured 2px of shadow on each side. Make the spread at least as negative as the blur, for example -6px with a 6px blur.

Is Tailwind's shadow-md bottom only?

No. shadow-md is heavier at the bottom but reaches about 5px on the left and right and 1px on top. For bottom only, use an arbitrary value like shadow-[0_8px_6px_-6px_rgb(0_0_0/0.2)] or define --shadow-bottom in @theme.

How do I make a box shadow on the top only?

Flip the vertical offset: box-shadow: 0 -8px 6px -6px rgb(0 0 0 / 0.2);. In Tailwind: shadow-[0_-8px_6px_-6px_rgb(0_0_0/0.2)].

Can I use clip-path instead of a negative spread?

Yes. clip-path: inset(0 0 -24px 0) on an element with a normal shadow cuts the shadow off on the top and sides and keeps a full-width shadow at the bottom. It also clips dropdowns and focus rings that stick out of the element, so it doesn't suit headers with menus.

Built on Tailwind CSS v4

1401 finished blocks on shadcn/ui, React and Astro

UI Pro, from €199

Build it with

Preview

Open the page
In UI Pro: get it, €199 once

With every block and theme. 400+ buyers since 2020. Plans

UI Pro

Build your next site from finished blocks

Every block, page template and website theme from €199, paid once, with every update and everything we add later. Not ready? The free blocks are open to everyone.

blocks
1401
page templates
55
website themes
29
The Case study page template from UI Pro, built from its blocks.

This page is built from UI Pro blocks: Zandloper (article-14), Rooilijn (call-to-action-07).