Kombai Logo

Tailwind CSS Drop Shadow

Drop Shadow is a CSS filter effect that applies a shadow to an element, simulating the effect of light and creating a sense of depth. Unlike traditional box shadows (box-shadow), the filter: drop-shadow() property applies shadows only to the visible parts of an element. This makes it especially useful for non-rectangular shapes, images, and elements with transparency.

Tailwind CSS offers utilities to easily apply filter: drop-shadow() effects. In this guide, we'll explore how to use these utilities, conditionally apply them, customize their behavior, and combine them with other Tailwind utilities to create visually engaging designs.

ClassPropertiesExample
drop-shadow-smfilter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.05));<div className="drop-shadow-sm"></div>
drop-shadowfilter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.1)) drop-shadow(0 1px 1px rgb(0 0 0 / 0.06));<div className="drop-shadow"></div>
drop-shadow-mdfilter: drop-shadow(0 4px 3px rgb(0 0 0 / 0.07)) drop-shadow(0 2px 2px rgb(0 0 0 / 0.06));<div className="drop-shadow-md"></div>
drop-shadow-lgfilter: drop-shadow(0 10px 8px rgb(0 0 0 / 0.04)) drop-shadow(0 4px 3px rgb(0 0 0 / 0.1));<div className="drop-shadow-lg"></div>
drop-shadow-xlfilter: drop-shadow(0 20px 13px rgb(0 0 0 / 0.03)) drop-shadow(0 8px 5px rgb(0 0 0 / 0.08));<div className="drop-shadow-xl"></div>
drop-shadow-2xlfilter: drop-shadow(0 25px 25px rgb(0 0 0 / 0.15));<div className="drop-shadow-2xl"></div>
drop-shadow-nonefilter: drop-shadow(0 0 #0000);<div className="drop-shadow-none"></div>

Overview of Drop Shadow

Adding the Drop Shadow

To apply a drop shadow to an element, simply use one of the pre-designed utilities like drop-shadow-sm, drop-shadow-md, drop-shadow-lg, etc.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Removing the Drop Shadow

If you need to remove the drop shadow from an element, use the drop-shadow-none utility. Alternatively, if you want to remove all the filters- use the filter-none utility.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

States and Responsiveness

Tailwind's state and responsive modifiers let you conditionally apply drop-shadow only on certain states and breakpoints.

Hover and Focus States

To create interactive shadows that respond to user actions like hovering or focusing, use state modifiers, e.g., hover:drop-shadow-md, focus:drop-shadow-lg, etc.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Breakpoint Modifiers

To use drop shadow only on certain breakpoint or above, use Tailwind's responsive modifiers, e.g., sm:drop-shadow-md, sm:drop-shadow-lg, etc.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Custom Drop Shadow

While Tailwind's built-in utilities are versatile, there might be cases where you require more control over shadow values. Tailwind enables you to create custom shadow configurations through theme extensions or use arbitrary values directly.

Extending the Theme

Custom shadow levels can be added to the theme configuration in your Tailwind tailwind.config.js file. This is useful for maintaining consistency across your project with unique design requirements.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Using Arbitrary Values

When extending the theme is not ideal for smaller, one-off use cases, you can apply arbitrary values directly. Tailwind supports inline configuration with square brackets [].

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Real World Examples

Product Showcase with Floating Cards

A modern e-commerce product grid where cards appear to float with drop shadows that intensify on hover.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Testimonial Cards with Layered Shadows

A testimonial section featuring cards with multiple layers of drop shadows for depth.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Feature Cards with Gradient Shadows

A cards section showcasing features with gradient backgrounds and custom drop shadows.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Pricing Table with Elevated Cards

A pricing table with cards that use drop shadows to create a floating effect.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Blog Post Cards with Dynamic Shadows

A blog post card section with shadows that respond to user interaction.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Customization Examples

Layered Card Drop Shadow

This example demonstrates a custom drop shadow configuration for a product card with multiple shadow layers, creating a sophisticated depth effect.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Directional Gradient Shadow

This example implements a custom gradient drop shadow that changes based on hover state, perfect for interactive cards.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Ambient Light Shadow

This example shows an ambient light source with dynamic shadows, perfect for creating depth in testimonial cards or pricing tables.

This is a live editor. Play around with it!
export default function App() {
  return <h1>Hello world</h1>
}

Best Practices

Maintain Design Consistency

Establishing predefined shadow styles for different UI elements, such as buttons, cards, and images, prevents inconsistency. If a subtle shadow effect is used in one section, other areas should not have exaggerated shadows unless necessary for a specific purpose. By defining clear shadow guidelines, projects maintain a professional appearance without unintentional visual disparities.

Maintaining consistency also means using shadows that align with the project's overall aesthetic. Soft and diffused shadows (drop-shadow-md, drop-shadow-lg) often work well in modern, minimalist designs, while stronger shadows (drop-shadow-xl) can be used for emphasis or interactive elements. Ensuring that shadows match the intended design language avoids distracting contrasts between elements.

Another way to maintain uniformity is by defining reusable Tailwind utility classes for commonly used shadow styles. This ensures that all components adhere to the same shadow hierarchy, reducing design fragmentation. Standardizing shadows through utility classes simplifies updates and keeps the design system organized and scalable.

Optimize for Reusability

Reusable components ensure efficient shadow management across a project. Instead of applying drop-shadow-* individually, encapsulating common shadow styles within reusable components improves maintainability. This approach reduces code duplication and ensures that design updates propagate consistently throughout the project.

For instance, a Card component can have a predefined shadow style applied consistently across all instances. If a design change requires adjusting the shadow intensity, modifying the component prop updates all instances without manual changes.

Accessibility Considerations

Enhance Readability and Navigability

Drop shadows can improve readability by subtly distinguishing elements from their background. Applying drop-shadow-md to cards, tooltips, or text containers enhances visual separation, making content easier to scan. Shadows can also help guide users’ eyes toward important elements, improving navigation flow.

Ensuring shadows do not reduce legibility is crucial. Overuse of dark shadows on already dark backgrounds or too subtle a shadow on a light interface can decrease contrast. Testing different shadow strengths in various lighting conditions ensures that content remains readable for all users.

Support Accessible Interactive Elements

Interactive elements such as buttons, links, and form inputs benefit from drop shadows when used appropriately. Shadows can enhance focus states (e.g., focus:drop-shadow-lg), making interactive elements easier to identify for keyboard users.

Ensuring that shadow-enhanced elements have sufficient padding and spacing prevents accidental interactions. Buttons and links should not have shadows so large that they obscure surrounding content or interfere with adjacent interactive elements.

Additionally, animations applied to shadows should not be too sudden or dramatic, as excessive motion may cause visual discomfort for some users. Keeping shadow effects subtle and controlled ensures a comfortable user experience.