You can apply a drop shadow to an element in Tailwind CSS by using the drop-shadow-*
utility classes.
To add a visual drop shadow effect to an element using Tailwind CSS, you utilize the built-in drop-shadow-*
utility classes.
Use the drop-shadow-* utilities to add a drop shadow to an element. These utilities are particularly useful for applying shadows to irregular shapes, such as text
elements or SVG
elements, where a standard box shadow might not produce the desired effect.
Tailwind provides a range of drop-shadow-*
classes to control the size and intensity of the shadow. Applying one of these classes directly to an HTML element will add the corresponding drop shadow filter effect.
Here are some common drop-shadow-*
utility classes you can use:
drop-shadow-sm
: Applies a small drop shadow.drop-shadow-md
: Applies a medium drop shadow (this is the default size if you just usedrop-shadow
).- **
drop-shadow-lg
: Applies a large drop shadow. drop-shadow-xl
: Applies an extra large drop shadow.drop-shadow-2xl
: Applies a very large drop shadow.drop-shadow-none
: Removes any existing drop shadow.
Example Usage:
<img src="your-svg.svg" class="drop-shadow-md" alt="An SVG with a medium drop shadow">
<p class="text-4xl font-bold drop-shadow-lg">Text with a large drop shadow</p>
Applying the drop-shadow-md
class to an image or drop-shadow-lg
to text, as shown above, adds the respective shadow effect.
Drop Shadow Utilities Overview
Class Name | Description |
---|---|
drop-shadow-sm |
Small drop shadow |
drop-shadow |
Default medium drop shadow (md ) |
drop-shadow-md |
Medium drop shadow |
drop-shadow-lg |
Large drop shadow |
drop-shadow-xl |
Extra large drop shadow |
drop-shadow-2xl |
Very large drop shadow |
drop-shadow-none |
No drop shadow |
These utilities leverage the CSS filter
property to apply the shadow, making them suitable for effects that follow the alpha channel of an element, which is ideal for non-rectangular content.