CSS Filters - Visual Effects for Images & Elements
What You'll Learn
Apply blur, brightness, and contrast filters to elements
Transform colors with grayscale, sepia, hue-rotate, and saturate
Use invert and opacity filters for creative effects
Create shape-aware shadows with drop-shadow()
Combine multiple filters for complex visual effects
Build interactive hover effects with smooth filter transitions
Understand the difference between drop-shadow() and box-shadow
Introduction to CSS Filters
CSS filters apply graphical effects like blur, color manipulation, and shadows to any element. Originally designed for image processing, filters work on all HTML elements including text, backgrounds, and SVG. Filters are GPU-accelerated for smooth performance and can be combined for sophisticated visual effects.
The filter property accepts one or more filter functions, each modifying the element's appearance in a specific way. Filters process in order, allowing layered effects.
blur() - Gaussian Blur Effect
The blur() filter applies Gaussian blur with a specified radius. Larger values create stronger blur. Accepts length values (px, rem, em) but not percentages.
The brightness() filter adjusts lightness from complete black (0) through normal (1) to infinitely bright. Values less than 1 darken; values greater than 1 lighten.
The contrast() filter adjusts the difference between light and dark areas. Values less than 1 reduce contrast (approaching gray); values greater than 1 increase contrast.
The hue-rotate() filter rotates colors around the color wheel. Accepts degree values from 0deg to 360deg, where 0deg/360deg returns to the original color.
The invert() filter creates negative images by reversing colors. The opacity() filter adjusts transparency, similar to the opacity property but processed as a filter.
Unlike box-shadow, the drop-shadow() filter creates shadows that follow the actual shape of elements, including transparency. Perfect for icons, SVG, and irregular shapes.
Multiple filter functions can be applied by listing them space-separated. Filters process from left to right, allowing complex layered effects.
/* Enhanced vibrant effect */
filter: brightness(1.2) contrast(1.3) saturate(1.5);
/* First brighten, then increase contrast, then boost saturation */
/* Vintage photograph */
filter: sepia(80%) contrast(1.2) brightness(0.9);
/* Sepia tone with enhanced contrast and slight darkening */
/* Dramatic black and white */
filter: grayscale(100%) contrast(1.8) brightness(1.1);
/* Convert to B&W with high contrast and slight brightening */
/* Glowing effect */
filter: brightness(1.2) saturate(1.3) drop-shadow(0 0 20px rgba(102, 126, 234, 0.6));
/* Brighten, saturate, then add glow */
/* Duotone effect */
filter: grayscale(100%) sepia(100%) hue-rotate(180deg) saturate(4);
/* Remove color, add sepia, shift hue, boost saturation */
/* Soft focus with enhancement */
filter: blur(1px) brightness(1.1) contrast(1.2) saturate(1.3);
/* Dark mode image adjustment */
filter: invert(100%) hue-rotate(180deg);
/* Frosted glass effect */
filter: blur(10px) brightness(1.2) saturate(1.5);
/* Order matters! */
filter: grayscale(100%) hue-rotate(90deg);
/* No visible effect - can't rotate hue of grayscale */
filter: hue-rotate(90deg) grayscale(100%);
/* Rotates hue THEN converts to grayscale - still appears gray */
Interactive Filter Effects
Combine filters with CSS transitions and hover states for smooth, engaging interactions. Filters transition smoothly, making them perfect for hover effects.