CSS

CSS Overview Selectors Declarations Rule Sets Comments Reset/Normalize Origin Importance Order Specificity Inheritance Cascade Layers Inline Styles Internal Styles External Styles @import Absolute Units Relative Units Dynamic Viewport Angle Units Time Units Frequency Units: Resolution Units Keywords Color Formats Color Functions & Spaces Background Color Background Image Background Repeat Background Position Background Size Background Attachment Background Shorthand Multiple Backgrounds Linear Gradients Radial Gradients Conic Gradients Font Family Font Size Font Weight Font Style Line Height Text Align Text Decoration Text Transform Letter Spacing Word Spacing Text Shadow Text Wrap Variable Fonts Content Box Padding Box Border Box Margin Box Box Sizing Property Margin Padding Border Outline Box Shadow Block Display Inline Display Inline Block Display Static Position Relative Position Absolute Position Fixed Position Sticky Position Top Element Position Right Element Position Bottom Element Position Left Element Position Z Index Flexbox Box Layout Display Flex Flex Direction Flex Wrap Justify Content Align Items Align Content Gap, Row Gap & Column Gap Flex Grow Flex Shrink Flex Basis Flex Shorthand Order Property Align Self Practical Applications CSS Grid Layout Grid Display Grid Template Columns Grid Template Rows Grid Template Areas Justify Items Grid Auto Columns Justify Self Nested Grids Responsive Web Design Min Width Max Width Orientation Logical Operators Pointer Hover Prefers Color Scheme Fluid Images Flexible Typography Viewport Width Advanced CSS Features Defining variables Using variables Scope & Inheritance of CSS Variables Property Value Fallback Practical Applications :Hover :Active :Focus :Focus Visible :Visited :Link :First Child :Last Child :Nth Child :Nth of Type :Empty :Checked :Disabled :Enabled :Valid :Invalid :Required :Has :Not :Is :Where ::Before Pseudo Element ::After Pseudo Element ::First Letter ::First Line ::Selection ::Marker CSS 2D Transformations CSS 3D Transformations Transform Origin Transform Style Backface Visibility Transition Property Transition Duration Transition Timing Function Transition Delay Transition Shorthand Ease Timing Function Linear Timing Function Ease In Timing Function Ease Out Timing Function Ease In Out Timing Function Cubic Bezier Function Animations (@keyframes) Defining @keyframes Animation Name CSS Animation Duration Animation Timing Function CSS Animation Delay CSS Animation Iteration Count Animations Direction CSS Animation Fill Mode CSS Animation Play State CSS Filter Blur CSS Filter Brightness CSS Filter Contrast() CSS Drop Shadow CSS Grayscale CSS Hue Rotate CSS Invert CSS Opacity CSS Saturate CSS Sepia Mix Blend Mode Background Blend Mode Object Fit & Object Position Scroll Snap Type Scroll Snap Align Scroll Padding Scroll Margin Scroll Triggered Animations JS Variables

CSS Drop Shadow


filter: drop-shadow()

The CSS filter property applies graphical effects like blurring or color shifting to an element. The drop-shadow() function creates a shadow that conforms to the shape of an element's content, unlike box-shadow which creates a rectangular shadow. This is particularly useful for creating shadows on transparent PNGs or complex shapes.


Example 1: Basic Drop Shadow

.basic-shadow {
  /* Applies a simple drop shadow */
  filter: drop-shadow(8px 8px 10px #555); /* offset-x | offset-y | blur-radius | color */
}

Explanation: This code adds a basic drop shadow to an element. The shadow is offset by 8 pixels horizontally and 8 pixels vertically, has a blur radius of 10 pixels, and its color is a dark gray.


Example 2: Colored Drop Shadow

.colored-shadow {
  /* Creates a blue, semi-transparent drop shadow */
  filter: drop-shadow(5px 5px 5px rgba(0, 0, 255, 0.6));
}

Explanation: This example demonstrates how to apply a colored shadow. We use an rgba() color value to create a semi-transparent blue shadow, allowing the background to show through.


Example 3: No Blur Drop Shadow

.no-blur-shadow {
  /* A sharp, solid drop shadow without any blur */
  filter: drop-shadow(10px 10px 0 #333); /* blur-radius is set to 0 */
}

Explanation: By setting the blur radius to 0, this code creates a crisp, hard-edged shadow. This effect can be used for creating a simple, stylized duplicate of the element's shape.


Example 4: Negative Offset Drop Shadow

.negative-offset-shadow {
  /* Shadow is cast to the top and left of the element */
  filter: drop-shadow(-6px -6px 8px #888);
}

Explanation: This code uses negative values for the horizontal and vertical offsets. This causes the shadow to appear to the top and left of the element, as if the light source is from the bottom right.


Example 5: Multiple Drop Shadows

.multiple-shadows {
  /* Layering multiple drop-shadow() functions for a unique effect */
  filter: drop-shadow(5px 5px 5px #f00) drop-shadow(-5px -5px 5px #00f);
}

Explanation: You can apply multiple drop-shadow() filters to a single element. In this example, a red shadow is cast to the bottom-right and a blue shadow is cast to the top-left, creating a layered, 3D-like effect.


Example 6: Drop Shadow on Hover

.hover-shadow {
  transition: filter 0.3s ease-in-out; /* Smooth transition for the filter property */
}

.hover-shadow:hover {
  /* A more prominent shadow appears on hover */
  filter: drop-shadow(0 0 15px rgba(255, 165, 0, 0.8));
}

Explanation: This example creates an interactive effect where the drop shadow appears or changes when the user hovers over the element. The transition property ensures the effect animates smoothly.


Example 7: Animating a Drop Shadow

@keyframes pulse {
  0% {
    filter: drop-shadow(0 0 5px #ffc107);
  }
  50% {
    filter: drop-shadow(0 0 20px #ffc107);
  }
  100% {
    filter: drop-shadow(0 0 5px #ffc107);
  }
}

.animated-shadow {
  /* Applies the pulsing animation to the drop shadow */
  animation: pulse 2s infinite;
}

Explanation: This code uses a @keyframes animation to create a "pulsing" glow effect. The drop-shadow() blur radius expands and contracts over two seconds, and the animation repeats indefinitely.